Skip to content
This repository has been archived by the owner on Feb 7, 2019. It is now read-only.

Fixes #10728: Add agent inventory name to parse in an inventory #106

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,25 @@ sealed abstract class AgentType {
// Tag used in fusion inventory ( > 2.3 )
lazy val tagValue = s"cfengine-${this}".toLowerCase
def toRulesPath() : String

// the name to look for in the inventory to know the agent version
def inventorySoftwareName: String
// and a transformation function from reported software version name to agent version name
def toAgentVersionName(softwareVersionName: String): String
}

final case object NOVA_AGENT extends AgentType with HashcodeCaching {
override def toString() = A_NOVA_AGENT
override def toRulesPath() = "/cfengine-nova"
override val inventorySoftwareName = "cfengine nova"
override def toAgentVersionName(softwareVersionName: String) = s"cfe-${softwareVersionName}"
}

final case object COMMUNITY_AGENT extends AgentType with HashcodeCaching {
override def toString() = A_COMMUNITY_AGENT
override def toRulesPath() = "/cfengine-community"
override val inventorySoftwareName = "rudder-agent"
override def toAgentVersionName(softwareVersionName: String) = softwareVersionName
}

object AgentType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,19 @@ class FusionReportUnmarshaller(

// as a temporary solution, we are getting information from packages

val versions = Map[AgentType, Option[AgentVersion]](
// for nova, we get the cfengine version, which not exactly what we want, but still better than nothing
(NOVA_AGENT , report.applications.find(p => p.name.getOrElse("").toLowerCase.contains("cfengine nova")).flatMap(s => s.version.map(v => AgentVersion("nova-" + v.value))))
// for community, we only want rudder-agent version
, (COMMUNITY_AGENT , report.applications.find(p => p.name.getOrElse("").toLowerCase.contains("rudder-agent")).flatMap(s => s.version.map(v => AgentVersion(v.value))))
)
val versions = {
def findAgent(software: Seq[Software], agentType: AgentType) = (
software.find(p => p.name.getOrElse("")
.toLowerCase.contains(agentType.inventorySoftwareName ))
.flatMap(s => s.version.map(v => AgentVersion(agentType.toAgentVersionName(v.value))))
)
Map[AgentType, Option[AgentVersion]](
// for nova, we get the cfengine version, which not exactly what we want, but still better than nothing
(NOVA_AGENT , findAgent(report.applications, NOVA_AGENT))
// for community, we only want rudder-agent version
, (COMMUNITY_AGENT , findAgent(report.applications, COMMUNITY_AGENT))
)
}


(xml \\ "RUDDER").headOption match {
Expand Down