Skip to content

Commit

Permalink
Fixes #5796: Make syslog transport configurable from web interface
Browse files Browse the repository at this point in the history
  • Loading branch information
VinceMacBuche committed Jun 9, 2015
1 parent 6a1dd0a commit 8e1b14c
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
Expand Up @@ -101,6 +101,7 @@ class SystemVariableServiceImpl(
, getCfengineOutputsTtl : () => Box[Int]
, getStoreAllCentralizedLogsInFile: () => Box[Boolean]
, getSendMetrics : () => Box[Option[Boolean]]
, getReportProtocol : () => Box[String]
) extends SystemVariableService with Loggable {

val varToolsFolder = systemVariableSpecService.get("TOOLS_FOLDER").toVariable().copyWithSavedValue(toolsFolder)
Expand Down Expand Up @@ -136,6 +137,7 @@ class SystemVariableServiceImpl(
val skipIdentify = getProp("SKIPIDENTIFY", getSkipIdentify)
val modifiedFilesTtl = getProp("MODIFIED_FILES_TTL", getModifiedFilesTtl)
val cfengineOutputsTtl = getProp("CFENGINE_OUTPUTS_TTL", getCfengineOutputsTtl)
val reportProtocol = getProp("REPORT_PROTOCOL", getReportProtocol)

val sendMetricsValue = if (getSendMetrics().getOrElse(None).getOrElse(false)) {
"yes"
Expand Down Expand Up @@ -177,6 +179,7 @@ class SystemVariableServiceImpl(
cfengineOutputsTtl ::
storeAllCentralizedLogsInFile ::
varSendMetrics ::
reportProtocol ::
Nil
vars.map(v => (v.spec.name,v)).toMap
}
Expand Down
Expand Up @@ -1267,6 +1267,7 @@ object RudderConfig extends Loggable {
, configService.cfengine_outputs_ttl _
, configService.rudder_store_all_centralized_logs_in_file _
, configService.send_server_metrics _
, configService.report_protocol _
)
private[this] lazy val rudderCf3PromisesFileWriterService = new RudderCf3PromisesFileWriterServiceImpl(
techniqueRepositoryImpl,
Expand Down
Expand Up @@ -133,6 +133,11 @@ trait ReadConfigService {
*/
def send_server_metrics(): Box[Option[Boolean]]

/**
* Report protocol
*/
def report_protocol(): Box[String]

}

/**
Expand Down Expand Up @@ -201,6 +206,11 @@ trait UpdateConfigService {

def set_rudder_compliance_heartbeatPeriod(frequency : Int, actor: EventActor, reason: Option[String]) : Box[Unit]

/**
* Report protocol
*/
def set_report_protocol(value : String): Box[Unit]

}

class LDAPBasedConfigService(configFile: Config, repos: ConfigRepository, workflowUpdate: AsyncWorkflowInfo) extends ReadConfigService with UpdateConfigService with Loggable {
Expand Down Expand Up @@ -229,6 +239,7 @@ class LDAPBasedConfigService(configFile: Config, repos: ConfigRepository, workfl
send.server.metrics=none
rudder.compliance.mode=${FullCompliance.name}
rudder.compliance.heartbeatPeriod=1
rudder.reports.protocol=tcp
"""

val configWithFallback = configFile.withFallback(ConfigFactory.parseString(defaultConfig))
Expand Down Expand Up @@ -392,4 +403,11 @@ class LDAPBasedConfigService(configFile: Config, repos: ConfigRepository, workfl
save("send_server_metrics",newVal,Some(info))
}


/**
* Report protocol
*/
def report_protocol(): Box[String] = get("rudder_reports_protocol")
def set_report_protocol(value : String): Box[Unit] = save("rudder_reports_protocol", value)

}
Expand Up @@ -83,6 +83,7 @@ class PropertiesManagement extends DispatchSnippet with Loggable {
case "cfengineGlobalProps" => cfengineGlobalProps
case "loggingConfiguration" => loggingConfiguration
case "sendMetricsConfiguration" => sendMetricsConfiguration
case "networkProtocolSection" => networkProtocolSection
}


Expand Down Expand Up @@ -469,6 +470,45 @@ class PropertiesManagement extends DispatchSnippet with Loggable {
) apply (xml ++ Script(Run("correctButtons();") & check()))
}

def networkProtocolSection = { xml : NodeSeq =>
// initial values, updated on successfull submit
var initReportsProtocol = configService.report_protocol
var reportProtocol = initReportsProtocol.getOrElse("tcp")
def check() = {
S.notice("updateNetworkProtocol","")
Run(s"""$$("#networkProtocolSubmit").button( "option", "disabled",${initReportsProtocol.map(_ == reportProtocol).getOrElse(false)});""")
}

def submit = {
configService.set_report_protocol(reportProtocol).foreach(updateOk => initReportsProtocol = Full(reportProtocol))

// start a promise generation, Since we check if there is change to save, if we got there it mean that we need to redeploy
startNewPolicyGeneration
S.notice("updateNetworkProtocol","Network protocol options correctly updated")
check()
}

( "#reportProtocol" #> {
initReportsProtocol match {
case Full(value) =>
SHtml.ajaxCheckbox(
value == "udp"
, (b : Boolean) => { reportProtocol = if (b) "udp" else "tcp"; check() }
, ("id","reportProtocol")
)
case eb: EmptyBox =>
val fail = eb ?~ "there was an error while fetching value of property: 'Report protocol' "
<div class="error">{fail.msg}</div>
}
} &

"#networkProtocolSubmit " #> {
SHtml.ajaxSubmit("Save changes", submit _)
}
) apply (xml ++ Script(Run("correctButtons();") & check()))

}

val agentScheduleEditForm = new AgentScheduleEditForm(
getSchedule
, saveSchedule
Expand Down
Expand Up @@ -118,6 +118,31 @@ <h3>Security</h3>
</div>
</div>
<hr class="spacer" />
<div class="deca">
<h3>Protocol</h3>
<div class="lift:administration.PropertiesManagement.networkProtocolSection" id="networkProtocolForm">
<form class="lift:form.ajax">
<div class="wbBaseField">
<label for="reportProtocol" class="threeCol textight" style="font-weight:bold;width: 50%;">
<span >Use UDP in place of TCP for syslog communication between node and servers:
<img src="/images/icInfo.png" style="padding-left:15px; margin:0; float:none" tooltipid="reportProtocolTooltip" title="" class="tooltipable" />
</span>
<div class="tooltipContent" id="reportProtocolTooltip">
Rudder uses syslog to transfer report messages from nodes to relay and
servers. By default, syslog uses TCP, which allows to minimize the loss in reports.
On the contrary, UDP allows to handle cases where the TCP connection does not respond and
may block syslog for the node.
</div>
</label>
<input id="reportProtocol" type="text"/>
</div>
<hr class="spacer"/>
<input type="submit" value="[save]" id="networkProtocolSubmit"/>
<lift:Msg id="updateNetworkProtocol">[messages]</lift:Msg>
</form>
</div>
</div>
<hr class="spacer" />


</div>
Expand Down

0 comments on commit 8e1b14c

Please sign in to comment.