Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ref #3297 : Add new columns to search node result (os details/ last repo... #127

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -170,7 +170,12 @@ object NodeEventLog {
<name>{node.name}</name>
<hostname>{node.hostname}</hostname>
<description>{node.description}</description>
<os>{node.os}</os>
<os>{node.osName}</os>
<osType>{node.osType}</osType>
<osVersion>{node.osVersion}</osVersion>
{node.servicePack.map(sp => <servicePack>{sp}</servicePack>)
.getOrElse(NodeSeq.Empty)}

<ips>{node.ips.map(ip => <ip>{ip}</ip>)}</ips>
<inventoryDate>{node.inventoryDate}</inventoryDate>
<publicKey>{node.publicKey}</publicKey>
Expand Down
Expand Up @@ -50,7 +50,10 @@ case class NodeInfo(
, name : String
, description : String
, hostname : String
, os : String
, osName : String
, osType : String
, osVersion : String
, servicePack : Option[String]
, ips : List[String]
, inventoryDate : DateTime
, publicKey : String
Expand Down
Expand Up @@ -106,6 +106,8 @@ trait ReportsRepository {

def getOldestArchivedReports() : Box[Option[Reports]]

def getNewestReportOnNode(nodeid:NodeId) : Box[Option[Reports]]

def getNewestReports() : Box[Option[Reports]]

def getNewestArchivedReports() : Box[Option[Reports]]
Expand Down
Expand Up @@ -234,6 +234,17 @@ class ReportsJdbcRepository(jdbcTemplate : JdbcTemplate) extends ReportsReposito
}
}

def getNewestReportOnNode(nodeid:NodeId) : Box[Option[Reports]] = {
jdbcTemplate.query(baseQuery + s" and nodeid = '${nodeid.value}' order by executionDate desc limit 1",
ReportsMapper).toSeq match {
case seq if seq.size > 1 => Failure("Too many answer for the latest report in the database")
case seq => Full(seq.headOption)

}
}



def getNewestReports() : Box[Option[Reports]] = {
jdbcTemplate.query(baseQuery + " order by executionTimeStamp desc limit 1",
ReportsMapper).toSeq match {
Expand Down
Expand Up @@ -98,7 +98,7 @@ class LDAPEntityMapper(

////////////////////////////// NodeInfo //////////////////////////////

val nodeInfoAttributes = Seq(A_OC, A_NODE_UUID, A_HOSTNAME, A_OS_FULL_NAME, A_NAME, A_POLICY_SERVER_UUID, A_LIST_OF_IP, A_OBJECT_CREATION_DATE,A_AGENTS_NAME,A_PKEYS, A_ROOT_USER)
val nodeInfoAttributes = Seq(A_OC, A_NODE_UUID, A_HOSTNAME,A_OS_NAME, A_OS_FULL_NAME,A_OS_SERVICE_PACK,A_OS_VERSION, A_NAME, A_POLICY_SERVER_UUID, A_LIST_OF_IP, A_OBJECT_CREATION_DATE,A_AGENTS_NAME,A_PKEYS, A_ROOT_USER)

/**
* From a nodeEntry and an inventoryEntry, create a NodeInfo
Expand All @@ -110,49 +110,62 @@ class LDAPEntityMapper(
def convertEntriesToNodeInfos(nodeEntry:LDAPEntry, inventoryEntry:LDAPEntry) : Box[NodeInfo] = {
//why not using InventoryMapper ? Some required things for node are not
// wanted here ?

for {
checkIsANode <- if(nodeEntry.isA(OC_RUDDER_NODE)) Full("ok") else Failure("Bad object class, need %s and found %s".format(OC_RUDDER_NODE,nodeEntry.valuesFor(A_OC)))
checkIsANode <- if(inventoryEntry.isA(OC_NODE)) Full("Ok") else Failure("Bad object class, need %s and found %s".format(OC_NODE,inventoryEntry.valuesFor(A_OC)))
checkSameID <-
if(nodeEntry(A_NODE_UUID).isDefined && nodeEntry(A_NODE_UUID) == inventoryEntry(A_NODE_UUID)) Full("Ok")
else Failure("Mismatch id for the node %s and the inventory %s".format(nodeEntry(A_NODE_UUID), inventoryEntry(A_NODE_UUID)))
id <- nodeDit.NODES.NODE.idFromDn(nodeEntry.dn) ?~! "Bad DN found for a Node: %s".format(nodeEntry.dn)
checkIsANode <- if(nodeEntry.isA(OC_RUDDER_NODE)) Full("ok")
else Failure("Bad object class, need %s and found %s".format(OC_RUDDER_NODE,nodeEntry.valuesFor(A_OC)))

checkIsANode <- if(inventoryEntry.isA(OC_NODE)) Full("Ok")
else Failure("Bad object class, need %s and found %s".format(OC_NODE,inventoryEntry.valuesFor(A_OC)))

checkSameID <- if(nodeEntry(A_NODE_UUID).isDefined && nodeEntry(A_NODE_UUID) == inventoryEntry(A_NODE_UUID)) Full("Ok")
else Failure("Mismatch id for the node %s and the inventory %s".format(nodeEntry(A_NODE_UUID), inventoryEntry(A_NODE_UUID)))

id <- nodeDit.NODES.NODE.idFromDn(nodeEntry.dn) ?~! "Bad DN found for a Node: %s".format(nodeEntry.dn)
// Compute the parent policy Id
policyServerId <- inventoryEntry.valuesFor(A_POLICY_SERVER_UUID).toList match {
case Nil => Failure("No policy servers for a Node: %s".format(nodeEntry.dn))
case x :: Nil => Full(x)
case _ => Failure("Too many policy servers for a Node: %s".format(nodeEntry.dn))
}
agentsName <- sequence(inventoryEntry.valuesFor(A_AGENTS_NAME).toSeq) { x =>
AgentType.fromValue(x) ?~! "Unknow value for agent type: '%s'. Authorized values are: %s".format(x, AgentType.allValues.mkString(", "))
case Nil => Failure("No policy servers for a Node: %s".format(nodeEntry.dn))
case x :: Nil => Full(x)
case _ => Failure("Too many policy servers for a Node: %s".format(nodeEntry.dn))
}

agentsName <- sequence(inventoryEntry.valuesFor(A_AGENTS_NAME).toSeq) { x =>
AgentType.fromValue(x) ?~!
"Unknow value for agent type: '%s'. Authorized values are: %s".format(x, AgentType.allValues.mkString(", "))
}
date <- nodeEntry.getAsGTime(A_OBJECT_CREATION_DATE) ?~! "Can not find mandatory attribute '%s' in entry".format(A_OBJECT_CREATION_DATE)
date <- nodeEntry.getAsGTime(A_OBJECT_CREATION_DATE) ?~!
"Can not find mandatory attribute '%s' in entry".format(A_OBJECT_CREATION_DATE)
osVersion = inventoryEntry(A_OS_VERSION).getOrElse("N/A")
osName = inventoryEntry(A_OS_NAME).getOrElse("N/A")
servicePack = inventoryEntry(A_OS_SERVICE_PACK)
osType = if(inventoryEntry.isA(OC_WINDOWS_NODE)) "Windows"
else if(inventoryEntry.isA(OC_LINUX_NODE)) "Linux"
else if(inventoryEntry.isA(OC_SOLARIS_NODE)) "Solaris"
else "Unknown"
} yield {
// fetch the inventory datetime of the object
val dateTime = inventoryEntry.getAsGTime(A_INVENTORY_DATE) match {
case None => DateTime.now()
case Some(date) => date.dateTime
}
val dateTime = inventoryEntry.getAsGTime(A_INVENTORY_DATE) map(_.dateTime) getOrElse(DateTime.now)

NodeInfo(
id,
nodeEntry(A_NAME).getOrElse(""),
nodeEntry(A_DESCRIPTION).getOrElse(""),
inventoryEntry(A_HOSTNAME).getOrElse(""),
//OsType.osTypeFromObjectClasses(inventoryEntry.valuesFor(A_OC)).map(_.toString).getOrElse(""),
inventoryEntry(A_OS_FULL_NAME).getOrElse(""),
inventoryEntry.valuesFor(A_LIST_OF_IP).toList,
dateTime,
inventoryEntry(A_PKEYS).getOrElse(""),
scala.collection.mutable.Seq() ++ agentsName,
NodeId(policyServerId),
//nodeDit.NODES.NODE.idFromDn(policyServerDN).getOrElse(error("Bad DN found for the policy server of Node: %s".format(nodeEntry.dn))),
inventoryEntry(A_ROOT_USER).getOrElse(""),
date.dateTime,
nodeEntry.getAsBoolean(A_IS_BROKEN).getOrElse(false),
nodeEntry.getAsBoolean(A_IS_SYSTEM).getOrElse(false),
nodeEntry.isA(OC_POLICY_SERVER_NODE)
id
, nodeEntry(A_NAME).getOrElse("")
, nodeEntry(A_DESCRIPTION).getOrElse("")
, inventoryEntry(A_HOSTNAME).getOrElse("")
//OsType.osTypeFromObjectClasses(inventoryEntry.valuesFor(A_OC)).map(_.toString).getOrElse(""),
, osName
, osType
, osVersion
, servicePack
, inventoryEntry.valuesFor(A_LIST_OF_IP).toList
, dateTime
, inventoryEntry(A_PKEYS).getOrElse("")
, scala.collection.mutable.Seq() ++ agentsName
, NodeId(policyServerId)
//nodeDit.NODES.NODE.idFromDn(policyServerDN).getOrElse(error("Bad DN found for the policy server of Node: %s".format(nodeEntry.dn))),
, inventoryEntry(A_ROOT_USER).getOrElse("")
, date.dateTime
, nodeEntry.getAsBoolean(A_IS_BROKEN).getOrElse(false)
, nodeEntry.getAsBoolean(A_IS_SYSTEM).getOrElse(false)
, nodeEntry.isA(OC_POLICY_SERVER_NODE)
)
}
}
Expand Down
Expand Up @@ -513,6 +513,9 @@ class EventLogDetailsServiceImpl(
(x \ "ip").toSeq.map( (y:NodeSeq) => y.text )
}?~! ("Missing attribute 'ips' in entry type node : " + entry)
os <- (details \ "os").headOption.map( _.text ) ?~! ("Missing attribute 'os' in entry type node : " + entry)
osType <- (details \ "osType").headOption.map( _.text ) ?~! ("Missing attribute 'os' in entry type node : " + entry)
osVersion <- (details \ "osVersion").headOption.map( _.text ) ?~! ("Missing attribute 'os' in entry type node : " + entry)
servicePack = (details \ "os").headOption.map( _.text )
boxedAgentsName<- (details \ "agentsName").headOption.map {
case x:NodeSeq =>
(x \ "agentName").toSeq.map( (y:NodeSeq) => AgentType.fromValue(y.text) )
Expand All @@ -533,7 +536,10 @@ class EventLogDetailsServiceImpl(
, name = name
, description = description
, hostname = hostname
, os = os
, os
, osType
, osVersion
, servicePack
, ips = ips.toList
, inventoryDate = ISODateTimeFormat.dateTimeParser.parseDateTime(inventoryDate)
, publicKey = publicKey
Expand Down
Expand Up @@ -83,7 +83,7 @@ class RemoveNodeServiceImpl(
nodeId = nodeInfo.id
, inventoryVersion = nodeInfo.inventoryDate
, hostname = nodeInfo.hostname
, fullOsName = nodeInfo.os
, fullOsName = nodeInfo.osName
, actorIp = actor.name
)
val eventlog = DeleteNodeEventLog.fromInventoryLogDetails(
Expand Down
Expand Up @@ -31,7 +31,7 @@
*
*************************************************************************************
*/

/*
package com.normation.rudder.services.nodes

import com.normation.inventory.domain.NodeId
Expand Down Expand Up @@ -78,4 +78,4 @@ class DummyNodeInfoService extends NodeInfoService {
def getAllSystemNodeIds() : Box[Seq[NodeId]] = {
Full(allNodes.filter(_.isPolicyServer).map(_.id))
}
}
}*/
11 changes: 6 additions & 5 deletions rudder-web/src/main/scala/bootstrap/liftweb/AppConfig.scala
Expand Up @@ -292,6 +292,7 @@ object RudderConfig extends Loggable {
val categoryHierarchyDisplayer: CategoryHierarchyDisplayer = categoryHierarchyDisplayerImpl
val dynGroupService: DynGroupService = dynGroupServiceImpl
val ditQueryData: DitQueryData = ditQueryDataImpl
val reportsRepository : ReportsRepository = reportsRepositoryImpl
val eventLogDeploymentService: EventLogDeploymentService = eventLogDeploymentServiceImpl
val allBootstrapChecks : BootstrapChecks = allChecks
val srvGrid = new SrvGrid
Expand Down Expand Up @@ -528,7 +529,7 @@ object RudderConfig extends Loggable {
private[this] lazy val modificationService = new ModificationService(logRepository,gitModificationRepository,itemArchiveManagerImpl,uuidGen)
private[this] lazy val eventListDisplayerImpl = new EventListDisplayer(eventLogDetailsServiceImpl, logRepository, roLdapNodeGroupRepository, roLdapDirectiveRepository, nodeInfoServiceImpl, modificationService, personIdentServiceImpl)
private[this] lazy val fileManagerImpl = new FileManager(UPLOAD_ROOT_DIRECTORY)
private[this] lazy val databaseManagerImpl = new DatabaseManagerImpl(reportsRepository)
private[this] lazy val databaseManagerImpl = new DatabaseManagerImpl(reportsRepositoryImpl)
private[this] lazy val softwareInventoryDAO: ReadOnlySoftwareDAO = new ReadOnlySoftwareDAOImpl(inventoryDitService, roLdap, inventoryMapper)
private[this] lazy val nodeSummaryServiceImpl = new NodeSummaryServiceImpl(inventoryDitService, inventoryMapper, roLdap)
private[this] lazy val diffRepos: InventoryHistoryLogRepository =
Expand Down Expand Up @@ -777,9 +778,9 @@ object RudderConfig extends Loggable {
techniqueRepositoryImpl,
RUDDER_DIR_LOCK)
private[this] lazy val licenseService: NovaLicenseService = new NovaLicenseServiceImpl(licenseRepository, ldapNodeConfigurationRepository, RUDDER_DIR_LICENSESFOLDER)
private[this] lazy val reportingServiceImpl = new ReportingServiceImpl(ruleTargetServiceImpl,configurationExpectedRepo, reportsRepository, techniqueRepositoryImpl)
private[this] lazy val reportingServiceImpl = new ReportingServiceImpl(ruleTargetServiceImpl,configurationExpectedRepo, reportsRepositoryImpl, techniqueRepositoryImpl)
private[this] lazy val configurationExpectedRepo = new com.normation.rudder.repository.jdbc.RuleExpectedReportsJdbcRepository(jdbcTemplate)
private[this] lazy val reportsRepository = new com.normation.rudder.repository.jdbc.ReportsJdbcRepository(jdbcTemplate)
private[this] lazy val reportsRepositoryImpl = new com.normation.rudder.repository.jdbc.ReportsJdbcRepository(jdbcTemplate)
private[this] lazy val dataSourceProvider = new RudderDatasourceProvider(RUDDER_JDBC_DRIVER, RUDDER_JDBC_URL, RUDDER_JDBC_USERNAME, RUDDER_JDBC_PASSWORD)
private[this] lazy val squerylDatasourceProvider = new SquerylConnectionProvider(dataSourceProvider.datasource)
private[this] lazy val jdbcTemplate = {
Expand Down Expand Up @@ -846,7 +847,7 @@ object RudderConfig extends Loggable {
, LDAPConstants.A_OS_SERVICE_PACK
, LDAPConstants.A_OS_KERNEL_VERSION
))
private[this] lazy val logDisplayerImpl: LogDisplayer = new LogDisplayer(reportsRepository, roLdapDirectiveRepository, roLdapRuleRepository)
private[this] lazy val logDisplayerImpl: LogDisplayer = new LogDisplayer(reportsRepositoryImpl, roLdapDirectiveRepository, roLdapRuleRepository)
private[this] lazy val categoryHierarchyDisplayerImpl: CategoryHierarchyDisplayer = new CategoryHierarchyDisplayer(roLdapNodeGroupRepository)
private[this] lazy val dyngroupUpdaterBatch: UpdateDynamicGroups = new UpdateDynamicGroups(
dynGroupServiceImpl
Expand Down Expand Up @@ -1010,7 +1011,7 @@ object RudderConfig extends Loggable {
, reportsRepository )
private[this] lazy val autoReportLogger = new AutomaticReportLogger(
propertyRepository
, reportsRepository
, reportsRepositoryImpl
, roLdapRuleRepository
, roLdapDirectiveRepository
, nodeInfoServiceImpl
Expand Down
Expand Up @@ -278,7 +278,7 @@ class SearchNodeComponent(
def showQueryAndGridContent() : NodeSeq = {
bind("content",searchNodes,
"query" -> {x:NodeSeq => displayQuery(x)},
"gridResult" -> srvGrid.display(Seq(), "serverGrid", Seq(), "") // we need to set something, or IE moans
"gridResult" -> srvGrid.display(Seq(), "serverGrid") // we need to set something, or IE moans
)
}
showQueryAndGridContent() ++ Script(OnLoad(ajaxGridRefresh))
Expand Down Expand Up @@ -316,12 +316,12 @@ class SearchNodeComponent(
// Ideally this would just check the size first ?
srvList match {
case Full(seq) =>
(srvGrid.display(seq, "serverGrid", Seq(), ""),
srvGrid.initJs("serverGrid", Seq(), "", false, true, onClickCallback))
(srvGrid.display(seq, "serverGrid"),
srvGrid.initJs("serverGrid", onClickCallback))

case Empty =>
(srvGrid.display(Seq(), "serverGrid", Seq(), ""),
srvGrid.initJs("serverGrid", Seq(), "", false, true, onClickCallback))
(srvGrid.display(Seq(), "serverGrid"),
srvGrid.initJs("serverGrid", onClickCallback))

case f@Failure(_,_,_) => (<div><h4>Error</h4>{f.messageChain}</div>, Noop)
}
Expand Down Expand Up @@ -521,7 +521,9 @@ object SearchNodeComponent {
ditQueryData.criteriaMap.get(x) foreach { o => if(i >= 0 && i < lines.size) lines(i) = lines(i).copy(objectType=o) }
}),
("id","ot_"+i),
("onchange", ajaxAttr(lines,i)._2.toJsCmd)
("onchange", ajaxAttr(lines,i)._2.toJsCmd),
("class","selectField")

)
}

Expand All @@ -533,7 +535,8 @@ object SearchNodeComponent {
if(i >= 0 && i < lines.size) lines(i).objectType.criterionForName(x) foreach { y => lines(i) = lines(i).copy(attribute=y) }
}),
("id","at_"+i),
("onchange", ajaxComp(lines,i)._2.toJsCmd)
("onchange", ajaxComp(lines,i)._2.toJsCmd),
("class","selectField")
)
}

Expand Down
Expand Up @@ -1125,7 +1125,7 @@ class EventListDisplayer(
"#name" #> details.node.name &
"#hostname" #> details.node.hostname &
"#description" #> details.node.description &
"#os" #> details.node.os &
"#os" #> details.node.osName &
"#ips" #> details.node.ips.mkString("\n") &
"#inventoryDate" #> DateFormaterService.getFormatedDate(details.node.inventoryDate) &
"#publicKey" #> details.node.publicKey &
Expand Down