XmlCollector Basic Authentication Example

This is an example configuration how to authenticate the XmlCollector with basic authentication base64 encoded method against Foremans API to collect the host status metric.

$OPENNMS_HOME/etc/collectd-configuration.xml

<service name="Foreman-Status" interval="300000" user-defined="false" status="on">
   <parameter key="collection" value="xml-foreman-stats" />
   <parameter key="handler-class" value="org.opennms.protocols.json.collector.DefaultJsonCollectionHandler" />
</service>

$OPENNMS_HOME/etc/xml-datacollection-config.xml

<xml-collection name="xml-foreman-stats">
   <rrd step="300">
      <rra>RRA:AVERAGE:0.5:1:2016</rra>
      <rra>RRA:AVERAGE:0.5:12:1488</rra>
      <rra>RRA:AVERAGE:0.5:288:366</rra>
      <rra>RRA:MAX:0.5:288:366</rra>
      <rra>RRA:MIN:0.5:288:366</rra>
   </rrd>
   <xml-source url="https://foreman_url/api/hosts/{nodelabel}/status/global">
      <request method="GET">
         <parameter name="timeout" value="6000" />
         <parameter name="retries" value="2" />
         <header name="Authorization" value="Basic dXNlcm5hbWU6cGFzc3dvcmQ" />
         <header name="Content-Type" value="application/json" />
      </request>
      <import-groups>xml-datacollection/foreman-stats.xml</import-groups>
   </xml-source>
</xml-collection>

:information_source: dXNlcm5hbWU6cGFzc3dvcmQ is the base64 encoded username:password string.

$OPENNMS_HOME/etc/xml-datacollection/foreman-stats.xml

<xml-groups>
   <xml-group name="status" resource-type="node" resource-xpath="/">
      <xml-object name="foremanStatus" type="GAUGE" xpath="status" />
   </xml-group>
</xml-groups>
1 Like