Project

General

Profile

« Previous | Next » 

Revision 10f0403b

Added by François ARMAND almost 7 years ago

Fixes #10931: Normalize agent names (cfengine-community, cfengine-nova, dsc)

View differences:

inventory-api/src/main/scala/com/normation/inventory/domain/AgentTypes.scala
package com.normation.inventory.domain
import InventoryConstants._
import net.liftweb.common._
import com.normation.utils.HashcodeCaching
/**
* The enumeration holding the values for the agent
*
*/
sealed abstract class AgentType {
def toString : String
def fullname : String
// Tag used in fusion inventory ( > 2.3 )
def tagValue : String
def toRulesPath : String
// the name to look for in the inventory to know the agent version
sealed trait AgentType {
/*
* this is the default agent identifier, the main name, used in:
* - in hooks: RUDDER_AGENT_TYPE: dsc (cfengine-community, cfengine-nova)
* - in technique metadata: <AGENT type="dsc">...</AGENT> (cfengine-community, cfengine-nova)
* - in serialisation
*/
def id: String
//yeah, you know, java
final override def toString() : String = id
/*
* This is the old, short name, which used to be used in LDAP "agentName"
* attribute and in (very old) fusion inventory reports (i.e: community, nova).
*/
def oldShortName: String
/*
* - in User facing UI: "Rudder (Windows DSC)" ("CFEngine Community" => "Rudder (CFEngine Community)", "CFEngine Enterprise")
*/
def displayName: String
/*
* - for policy generation: /var/rudder/share/xxxx/rules/dsc (/rules/cfengine-community, /rules/cfengine-nova)
*/
def toRulesPath: String
/*
* This is the list of <AGENTNAME> to look for in fusion inventory report of LDAP
* to choose the agent type.
* - in inventory report: <AGENTNAME>dsc</AGENTNAME> ("Community" => "cfengine-community", "Nova" => "cfengine-nova")
* - in LDAP agentName attribute
* This is a set, because we want to accept renaming along the way.
* Everything must be lower case in it.
* It is most likely Set(id, oldShortName)
*/
def inventoryAgentNames: Set[String]
/*
* the name to look for in the inventory to know the agent version (when not reported in <AGENT><VERSION>)
* - for inventory software name (i.e package name in software): rudder-agent-dsc ("rudder-agent", "cfengine nova")
*/
def inventorySoftwareName: String
// and a transformation function from reported software version name to agent version name
// and a transformation function from reported software version name to agent version name, internal use only
def toAgentVersionName(softwareVersionName: String): String
}
object AgentType {
final case object CfeEnterprise extends AgentType with HashcodeCaching {
override def toString = A_NOVA_AGENT
override def fullname : String = "CFEngine "+this
override def tagValue = s"cfengine-${A_NOVA_AGENT}".toLowerCase
override def toRulesPath = "/cfengine-nova"
final case object CfeEnterprise extends AgentType {
override def id = "cfengine-nova"
override def oldShortName = "nova"
override def displayName = "CFEngine Enterprise"
override def toRulesPath = "/cfengine-nova"
override def inventoryAgentNames = Set("cfengine-nova", "nova")
override val inventorySoftwareName = "cfengine nova"
override def toAgentVersionName(softwareVersionName: String) = s"cfe-${softwareVersionName}"
}
final case object CfeCommunity extends AgentType with HashcodeCaching {
override def toString = A_COMMUNITY_AGENT
override def fullname : String = "CFEngine "+this
override def tagValue = s"cfengine-${A_COMMUNITY_AGENT}".toLowerCase
override def toRulesPath = "/cfengine-community"
final case object CfeCommunity extends AgentType {
override def id = "cfengine-community"
override def oldShortName = "community"
override def displayName = "Rudder (CFEngine Community)"
override def toRulesPath = "/cfengine-community"
override def inventoryAgentNames = Set("cfengine-community", "community")
override val inventorySoftwareName = "rudder-agent"
override def toAgentVersionName(softwareVersionName: String) = softwareVersionName
}
final case object Dsc extends AgentType with HashcodeCaching {
override def toString = A_DSC_AGENT
override def fullname : String = "Rudder Windows DSC"
override def tagValue = "windows-dsc"
override def toRulesPath = "/dsc"
override val inventorySoftwareName = "Rudder agent"
override def toAgentVersionName(softwareVersionName: String) = softwareVersionName+" (dsc)"
final case object Dsc extends AgentType {
override def id = "dsc"
override def oldShortName = "dsc"
override def displayName = "Rudder (Windows DSC)"
override def toRulesPath = "/dsc"
override def inventoryAgentNames = Set("dsc")
override val inventorySoftwareName = "rudder-agent-dsc"
override def toAgentVersionName(softwareVersionName: String) = softwareVersionName
}
def allValues = CfeEnterprise :: CfeCommunity :: Dsc :: Nil
def allValues = ca.mrvisser.sealerate.values[AgentType]
def fromValue(value : String) : Box[AgentType] = {
// Check if the value is correct compared to the agent tag name (fusion > 2.3) or its toString value (added by CFEngine)
def checkValue( agent : AgentType) = {
value.toLowerCase == agent.toString.toLowerCase || value.toLowerCase == agent.tagValue.toLowerCase
agent.inventoryAgentNames.contains(value.toLowerCase)
}
allValues.find(checkValue) match {
case None => Failure(s"Wrong type of value for the agent '${value}'")
case None => Failure(s"Wrong type of value for the agent '${value}'")
case Some(agent) => Full(agent)
}
}
......
final case class AgentVersion(value: String)
final case class AgentInfo(
agentType : AgentType
agentType : AgentType
//for now, the version must be an option, because we don't add it in the inventory
//and must try to find it from packages
, version : Option[AgentVersion]
......
def toJsonString =
compactRender(
("agentType" -> agent.agentType.toString())
("agentType" -> agent.agentType.id)
~ ("version" -> agent.version.map( _.value ))
~ ("securityToken" ->
("value" -> agent.securityToken.key)
inventory-api/src/main/scala/com/normation/inventory/domain/InventoryConstants.scala
/*
*************************************************************************************
* Copyright 2011 Normation SAS
*************************************************************************************
*
* This file is part of Rudder.
*
* Rudder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In accordance with the terms of section 7 (7. Additional Terms.) of
* the GNU General Public License version 3, the copyright holders add
* the following Additional permissions:
* Notwithstanding to the terms of section 5 (5. Conveying Modified Source
* Versions) and 6 (6. Conveying Non-Source Forms.) of the GNU General
* Public License version 3, when you create a Related Module, this
* Related Module is not considered as a part of the work and may be
* distributed under the license agreement of your choice.
* A "Related Module" means a set of sources files including their
* documentation that, without modification of the Source Code, enables
* supplementary functions or services in addition to those offered by
* the Software.
*
* Rudder is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Rudder. If not, see <http://www.gnu.org/licenses/>.
*
*************************************************************************************
*/
package com.normation.inventory.domain
object InventoryConstants {
val A_NOVA_AGENT = "Nova"
val A_COMMUNITY_AGENT = "Community"
val A_DSC_AGENT = "windows-dsc"
}
inventory-fusion/src/main/scala/com/normation/inventory/provisioning/fusion/FusionReportUnmarshaller.scala
import com.normation.inventory.domain._
import com.normation.inventory.domain.AgentType._
import com.normation.inventory.provisioning.fusion._
import java.io.InputStream
import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
import java.util.Locale
import com.normation.inventory.domain.NodeTimezone
import com.normation.inventory.services.provisioning._
import com.normation.utils.StringUuidGenerator
import com.normation.utils.Utils._
import java.net.InetAddress
import scala.xml._
import org.xml.sax.SAXParseException
import java.util.Locale
import net.liftweb.common._
import com.normation.inventory.domain.InventoryConstants._
import com.normation.inventory.services.provisioning._
import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
import org.joda.time.format.DateTimeFormatter
import com.normation.utils.Control.sequence
import com.normation.inventory.domain.NodeTimezone
import scala.xml._
class FusionReportUnmarshaller(
uuidGen:StringUuidGenerator,
......
}
def processNetworks(n : NodeSeq) : Option[Network] = {
import InetAddressUtils._
import com.normation.inventory.domain.InetAddressUtils._
//in fusion report, we may have several IP address separated by comma
def getAddresses(addressString : String) : Seq[InetAddress] = {
for {
inventory-fusion/src/test/resources/fusion-report/dsc-agent.ocs
</PRINTERS>
<RUDDER>
<AGENT>
<AGENT_NAME>windows-dsc</AGENT_NAME>
<AGENT_NAME>dsc</AGENT_NAME>
<AGENT_CERT>-----BEGIN CERTIFICATE-----
MIIE0zCCArugAwIBAgIJAJqeHdZEkElqMA0GCSqGSIb3DQEBCwUAMBExDzANBgNV
BAMMBkFHRU5UMTAeFw0xNzA2MDcxMzA1NTlaFw0yNzA2MDUxMzA1NTlaMBExDzAN
inventory-fusion/src/test/scala/com/normation/inventory/provisioning/fusion/TestReportParsing.scala
"Agent in Inventory" should {
"should be empty when there is no agent" in {
"be empty when there is no agent" in {
val agents = parser.parse("fusion-report/rudder-tag/minimal-zero-agent.ocs").node.agents.map(_.agentType).toList
agents must be empty
}
"should have one agent when using community" in {
"have one agent when using community" in {
val agents = parser.parse("fusion-report/rudder-tag/minimal-one-agent.ocs").node.agents.map(_.agentType).toList
agents == (CfeCommunity :: Nil)
}
"should have two agent when using community and nova" in {
"have two agent when using community and nova" in {
val agents = parser.parse("fusion-report/rudder-tag/minimal-two-agents.ocs").node.agents.map(_.agentType).toList
agents == (CfeCommunity :: CfeEnterprise :: Nil)
}
"should be empty when there is two agents, using two different policy servers" in {
"be empty when there is two agents, using two different policy servers" in {
val agents = parser.parse("fusion-report/rudder-tag/minimal-two-agents-fails.ocs").node.agents.map(_.agentType).toList
agents must be empty
}
"should have dsc agent agent when using rudder-agent based on dsc" in {
"have dsc agent agent when using rudder-agent based on dsc" in {
val agents = parser.parse("fusion-report/dsc-agent.ocs").node.agents.map(_.agentType).toList
agents == (Dsc :: Nil)
}
inventory-repository/src/main/scala/com/normation/inventory/ldap/core/InventoryMapper.scala
import LDAPConstants._
import com.normation.inventory.domain._
import com.unboundid.ldap.sdk.{Version => UVersion, _ }
import com.unboundid.ldap.sdk.{Version => _, _ }
import com.normation.ldap.sdk._
import com.normation.ldap.sdk.schema.LDAPObjectClass
import org.joda.time.DateTime
......
import net.liftweb.json._
import Box._
import java.net.InetAddress
import java.net.UnknownHostException
import InetAddressUtils._
import com.normation.utils.Control.sequence
import com.normation.inventory.domain.NodeTimezone

Also available in: Unified diff