Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ncharles committed Jun 27, 2019
1 parent c2dcde4 commit 4a84d37
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,13 @@ attributetype ( RudderAttributes:353
EQUALITY caseExactMatch
SUBSTR caseIgnoreSubstringsMatch )

attributetype ( RudderAttributes:354
NAME 'agentReportingProtocol'
DESC 'Protocol used by agent for reporting'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
EQUALITY caseExactMatch
SUBSTR caseIgnoreSubstringsMatch )

#######################################################
################ Object Classes ######################
#######################################################
Expand All @@ -467,7 +474,7 @@ objectclass ( RudderObjectClasses:1
STRUCTURAL
MUST ( nodeId $ cn $ isSystem )
MAY ( description $ serializedNodeProperty $ serializedAgentRunInterval $
serializedHeartbeatRunConfiguration $ policyMode $ state $ isBroken) )
serializedHeartbeatRunConfiguration $ agentReportingProtocol $ policyMode $ state $ isBroken) )

objectclass ( RudderObjectClasses:2
NAME 'rudderPolicyServer'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,6 @@ class SystemVariableSpecServiceImpl extends SystemVariableSpecService {
"SEND_METRICS" , "Should the server agent send metrics to Rudder development team"
, multivalued = false
)
, SystemVariableSpec(
"RUDDER_SYSLOG_PROTOCOL" , "Which protocol should syslog use"
, multivalued = false
)
, SystemVariableSpec(
"RUDDER_SYSTEM_DIRECTIVES_SEQUENCE" , "The sequence of bundle to use as method call in bundle rudder_system_directives, in a formatted string"
, multivalued = false
Expand Down Expand Up @@ -307,6 +303,20 @@ class SystemVariableSpecServiceImpl extends SystemVariableSpecService {
"AGENT_TYPE" , "The normalised name of the agent type (cfengine-community, dsc, etc)"
, multivalued = false
)
// Configure node protocol, SYLOG or HTTPS
, SystemVariableSpec(
"REPORTING_PROTOCOL" , "Protocol used by agent to send reports (HTTPS or SYSLOG)"
, multivalued = false
)
, SystemVariableSpec(
"RUDDER_SYSLOG_PROTOCOL" , "Protocol ued by syslog (TCP or UDP)"
, multivalued = false
)
, SystemVariableSpec(
"SYSLOG_PROTOCOL_DISABLED" , "Syslog protocol totally disabled"
, multivalued = false
, constraint = Constraint(typeName = BooleanVType, default=Some("false"))
)
)

private[this] val varSpecsMap = varSpecs.map(x => (x.name -> x)).toMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ object RudderLDAPConstants extends Loggable {

val A_SERIALIZED_AGENT_RUN_INTERVAL = "serializedAgentRunInterval"
val A_SERIALIZED_HEARTBEAT_RUN_CONFIGURATION = "serializedHeartbeatRunConfiguration"
val A_AGENT_REPORTING_PROTOCOL = "agentReportingProtocol"

val A_POLICY_MODE = "policyMode"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ case object Node {
, false
, false
, inventory.node.inventoryDate.getOrElse(new DateTime(0))
, ReportingConfiguration(None,None)
, ReportingConfiguration(None,None, None)
, Seq()
, None
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ final case class NodeInfo(
val nodeReportingConfiguration = node.nodeReportingConfiguration
val properties = node.properties
val policyMode = node.policyMode

/**
* Get a digest of the key in the proprietary CFEngine digest format. It is
* formated as expected by CFEngine authentication module, i.e with the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import com.normation.rudder.domain.Constants
final case class ReportingConfiguration(
agentRunInterval : Option[AgentRunInterval]
, heartbeatConfiguration: Option[HeartbeatConfiguration]
, agentReportingProtocol: Option[AgentReportingProtocol]
) extends HashcodeCaching

final case class HeartbeatConfiguration(
Expand Down Expand Up @@ -166,3 +167,27 @@ object SyslogTCP extends SyslogProtocol {
object SyslogUDP extends SyslogProtocol {
val value = "UDP"
}

sealed trait AgentReportingProtocol {
def value : String
}

object AgentReportingHTTPS extends AgentReportingProtocol {
val value = "HTTPS"
}

object AgentReportingSyslog extends AgentReportingProtocol {
val value = "SYSLOG"
}

object AgentReportingProtocol {
val defaultValue = AgentReportingSyslog

This comment has been minimized.

Copy link
@ncharles

ncharles Jun 27, 2019

Author Owner

default value is hardcoded, i'm not sure i can do otherwise


def apply(value: String): AgentReportingProtocol = {
value match {
case AgentReportingHTTPS.value => AgentReportingHTTPS
case AgentReportingSyslog.value => AgentReportingSyslog
case _ => defaultValue
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ class LDAPEntityMapper(
case _ =>
}

node.nodeReportingConfiguration.agentReportingProtocol match {
case Some(protocol) => entry +=! (A_AGENT_REPORTING_PROTOCOL, protocol.value)
case _ =>
}

// for node properties, we ALWAYS filter-out properties coming from inventory,
// because we don't want to store them there.
entry +=! (A_NODE_PROPERTY, node.properties.collect { case p if(p.provider != Some(NodeProperty.customPropertyProvider)) => compactRender(p.toJson)}:_* )
Expand Down Expand Up @@ -178,6 +183,7 @@ class LDAPEntityMapper(
date <- e.requiredAs[GeneralizedTime]( _.getAsGTime, A_OBJECT_CREATION_DATE)
agentRunInterval = e(A_SERIALIZED_AGENT_RUN_INTERVAL).map(unserializeAgentRunInterval(_))
heartbeatConf = e(A_SERIALIZED_HEARTBEAT_RUN_CONFIGURATION).map(unserializeNodeHeartbeatConfiguration(_))
agentReportingProtocol = e(A_AGENT_REPORTING_PROTOCOL).map(AgentReportingProtocol(_))
policyMode <- e(A_POLICY_MODE) match {
case None => Right(None)
case Some(value) => PolicyMode.parse(value).map {Some(_) }
Expand Down Expand Up @@ -205,6 +211,7 @@ class LDAPEntityMapper(
, ReportingConfiguration(
agentRunInterval
, heartbeatConf
, agentReportingProtocol
)
, properties
, policyMode
Expand Down Expand Up @@ -251,7 +258,7 @@ class LDAPEntityMapper(
, inventoryEntry.getAsBoolean(A_IS_SYSTEM).getOrElse(false)
, false //we don't know anymore if it was a policy server
, new DateTime(0) // we don't know anymore the acceptation date
, ReportingConfiguration(None, None) //we don't know anymore agent run frequency
, ReportingConfiguration(None, None, None) //we don't know anymore agent run frequency
, Seq() //we forgot node properties
, None
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ import com.normation.rudder.domain.logger.ApplicationLogger
import com.normation.rudder.domain.nodes.NodeInfo
import com.normation.rudder.domain.policies.GroupTarget
import com.normation.rudder.domain.policies.RuleTarget
import com.normation.rudder.reports.AgentRunInterval
import com.normation.rudder.reports.ChangesOnly
import com.normation.rudder.reports.ComplianceMode
import com.normation.rudder.reports.SyslogProtocol
import com.normation.rudder.reports._
import com.normation.rudder.repository.FullNodeGroupCategory
import com.normation.rudder.services.servers.PolicyServerManagementService
import com.normation.rudder.services.servers.RelaySynchronizationMethod
Expand Down Expand Up @@ -132,6 +129,7 @@ class SystemVariableServiceImpl(
, getStoreAllCentralizedLogsInFile: () => Box[Boolean]
, getSendMetrics : () => Box[Option[Boolean]]
, getSyslogProtocol : () => Box[SyslogProtocol]
, getSyslogProtocolDisabled : () => Box[Boolean]
) extends SystemVariableService with Loggable {

import SystemVariableService._
Expand Down Expand Up @@ -182,6 +180,8 @@ class SystemVariableServiceImpl(
val relaySyncPromises = getProp("RELAY_SYNC_PROMISES" , getSyncPromises)
val relaySyncSharedFiles = getProp("RELAY_SYNC_SHAREDFILES", getSyncSharedFiles)

val syslogProtocolDisabled = getProp("SYSLOG_PROTOCOL_DISABLED", getSyslogProtocolDisabled)

val sendMetricsValue = if (getSendMetrics().getOrElse(None).getOrElse(false)) {
"yes"
} else {
Expand Down Expand Up @@ -440,7 +440,6 @@ class SystemVariableServiceImpl(

val varManagedNodesCertUUID = systemVariableSpecService.get("MANAGED_NODES_CERT_UUID").toVariable(nodesWithCertificate.map(_._1.id.value))


//Reports DB (postgres) DB name and DB user
val varReportsDBname = systemVariableSpecService.get("RUDDER_REPORTS_DB_NAME").toVariable(Seq(reportsDbName))
val varReportsDBuser = systemVariableSpecService.get("RUDDER_REPORTS_DB_USER").toVariable(Seq(reportsDbUser))
Expand Down Expand Up @@ -523,6 +522,14 @@ class SystemVariableServiceImpl(
val varNodeGroups = systemVariableSpecService.get("RUDDER_NODE_GROUPS_VARS").toVariable(Seq(stringNodeGroupsVars))
val varNodeGroupsClasses = systemVariableSpecService.get("RUDDER_NODE_GROUPS_CLASSES").toVariable(Seq(stringNodeGroupsClasses))

val reportingProtocol = getSyslogProtocolDisabled() match {
case Full(true) => AgentReportingHTTPS
case Full(false) => nodeInfo.nodeReportingConfiguration.agentReportingProtocol.getOrElse(AgentReportingProtocol.defaultValue)
case f: Failure => logger.error (s"Failed to get information on syslog protocol global status, fallbacking to default value. Cause is ${f.messageChain}")
AgentReportingProtocol.defaultValue
}
val varNodeReportingProtocol = systemVariableSpecService.get("REPORTING_PROTOCOL").toVariable(Seq(reportingProtocol.value))

val baseVariables = {
Seq(
varNodeRole
Expand All @@ -531,6 +538,7 @@ class SystemVariableServiceImpl(
, varNodeConfigVersion
, varNodeGroups
, varNodeGroupsClasses
, varNodeReportingProtocol
) map (x => (x.spec.name, x))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ class AcceptFullInventoryInNodeOu(
, false
, isPolicyServer
, DateTime.now // won't be used on save - dummy value
, ReportingConfiguration(None,None) // use global schedule
, ReportingConfiguration(None,None, None) // use global schedule, and default configuration for reporting
, Seq() //no user properties for now
, defaultPolicyMode().openOr(None)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,12 @@ attributeTypes: ( 1.3.6.1.4.1.35061.2.1.353
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
EQUALITY caseExactMatch
SUBSTR caseIgnoreSubstringsMatch )
attributeTypes: ( 1.3.6.1.4.1.35061.2.1.354
NAME 'agentReportingProtocol'
DESC 'Protocol used by agent for reporting'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
EQUALITY caseExactMatch
SUBSTR caseIgnoreSubstringsMatch )
#######################################################
################ Object Classes ######################
#######################################################
Expand All @@ -382,7 +388,7 @@ objectClasses: ( 1.3.6.1.4.1.35061.2.2.1
STRUCTURAL
MUST ( nodeId $ cn $ isSystem )
MAY ( description $ serializedNodeProperty $ serializedAgentRunInterval $
serializedHeartbeatRunConfiguration $ policyMode $ state $ isBroken) )
serializedHeartbeatRunConfiguration $ agentReportingProtocol $ policyMode $ state $ isBroken) )
objectClasses: ( 1.3.6.1.4.1.35061.2.2.2
NAME 'rudderPolicyServer'
DESC 'The Node representation of a policy server'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RuleTargetTest extends Specification with Loggable {
NodeId(s"${i}")
}).toSet

def newNode(id : NodeId) = Node(id,"" ,"", NodeState.Enabled, false, false, DateTime.now, ReportingConfiguration(None,None), Seq(), None)
def newNode(id : NodeId) = Node(id,"" ,"", NodeState.Enabled, false, false, DateTime.now, ReportingConfiguration(None,None, None), Seq(), None)

val allNodeIds = nodeIds + NodeId("root")
val nodes = allNodeIds.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ hMQjrt9gW2qJpxZyFoPuMsWFIaX4wrN7Y8ZiN37U2q1G11tv2oQlJTQeiYaUnTX4
z5VEb9yx2KikbWyChM1Akp82AV5BzqE80QIBIw==
-----END RSA PUBLIC KEY-----"""

val emptyNodeReportingConfiguration = ReportingConfiguration(None,None)
val emptyNodeReportingConfiguration = ReportingConfiguration(None,None, None)

val id1 = NodeId("node1")
val hostname1 = "node1.localhost"
Expand Down Expand Up @@ -370,7 +370,7 @@ z5VEb9yx2KikbWyChM1Akp82AV5BzqE80QIBIw==
NodeId(s"${i}")
}).toSet

def newNode(id : NodeId) = Node(id,"" ,"", NodeState.Enabled, false, false, DateTime.now, ReportingConfiguration(None,None), Seq(), None)
def newNode(id : NodeId) = Node(id,"" ,"", NodeState.Enabled, false, false, DateTime.now, ReportingConfiguration(None,None, None), Seq(), None)

val nodes = (Set(root, node1, node2) ++ nodeIds.map {
id =>
Expand Down Expand Up @@ -547,6 +547,7 @@ class TestNodeConfiguration() {
, getStoreAllCentralizedLogsInFile= () => Full(true)
, getSendMetrics = () => Full(None)
, getSyslogProtocol = () => Full(SyslogUDP)
, getSyslogProtocolDisabled = () => Full(false)
)

//a test node - CFEngine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ trait ReadConfigService {
*/
def rudder_syslog_protocol(): IOResult[SyslogProtocol]

/**
* Report protocol
*/
def rudder_syslog_protocol_disabled(): IOResult[Boolean]

/**
* Should we display recent changes graphs ?
*/
Expand Down Expand Up @@ -297,6 +302,8 @@ trait UpdateConfigService {
*/
def set_rudder_syslog_protocol(value : SyslogProtocol, actor : EventActor, reason: Option[String]): IOResult[Unit]

def set_rudder_syslog_protocol_disabled(value : Boolean, actor : EventActor, reason: Option[String]): IOResult[Unit]

/**
* Should we display recent changes graphs ?
*/
Expand Down Expand Up @@ -385,6 +392,7 @@ class LDAPBasedConfigService(
rudder.compliance.mode=${FullCompliance.name}
rudder.compliance.heartbeatPeriod=1
rudder.syslog.protocol=UDP
rudder.syslog.protocol.disabled=false
display.changes.graph=true
rudder.ui.display.ruleComplianceColumns=false
rudder.policy.mode.name=${Enforce.name}
Expand Down Expand Up @@ -626,6 +634,12 @@ class LDAPBasedConfigService(
save("rudder_syslog_protocol", protocol.value, Some(info))
}

def rudder_syslog_protocol_disabled(): IOResult[Boolean] = get("rudder_syslog_protocol_disabled")
def set_rudder_syslog_protocol_disabled(disabled : Boolean, actor : EventActor, reason: Option[String]): IOResult[Unit] = {
val info = ModifyGlobalPropertyInfo(ModifyRudderSyslogProtocolEventType,actor,reason)
save("rudder_syslog_protocol_disabled", disabled, Some(info))
}

/**
* Should we display recent changes graphs ?
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,12 @@ class SettingsApi(
}
}
}
case object RestSyslogProtocolDisabled extends RestBooleanSetting {
val key = "syslog_protocol_disabled"
val startPolicyGeneration = true
def get = configService.rudder_syslog_protocol_disabled()
def set = (value : Boolean, actor : EventActor, reason : Option[String]) => configService.set_rudder_syslog_protocol_disabled(value, actor, reason)
}
case object RestChangesGraphs extends RestBooleanSetting {
val startPolicyGeneration = false
val key = "display_recent_changes_graphs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,7 @@ object RudderConfig extends Loggable {
, () => configService.rudder_store_all_centralized_logs_in_file().toBox
, () => configService.send_server_metrics().toBox
, () => configService.rudder_syslog_protocol().toBox
, () => configService.rudder_syslog_protocol_disabled().toBox
)
private[this] lazy val rudderCf3PromisesFileWriterService = new PolicyWriterServiceImpl(
techniqueRepositoryImpl
Expand Down

0 comments on commit 4a84d37

Please sign in to comment.