Puppet Class: librenms::device
- Defined in:
- manifests/device.pp
Overview
Class: librenms::device
This class is used to export an Exec resource that adds this node to librenms.
Note that this class makes quite a few assumptions regarding snmpv3 to simplify the code:
-
Both authentication and encryption are used with snmpv3
-
SHA is used for authentication
-
AES is used for encryption
-
Both authentication and encryption are required
-
The snmp daemon is listening on the default port
Parameters
- manage
-
Whether to add this node to LibreNMS. Valid values are true (default) and false. You probably want to set this to false if you’re including this class on test nodes.
- librenms_basedir
-
The directory into which LibreNMS is installed on the server side. Defaults to ‘/opt/librenms’.
- community
-
The community string to use with SNMPv2©. Leave empty (default) to disable snmpv2.
- user
-
Snmpv3 username. Leave empty (default) to not use snmpv3.
- pass
-
Snmpv3 user password. Leave empty (default) to not use snmpv3.
- proto
-
Snmp protocol version. Valid values are ‘v1’, ‘v2c’ and ‘v3’ (default). This parameter is here primarily to reduce the conditional logic in this class.
- realize
-
Do not export the Exec that joins this node to LibreNMS. Instead run it directly. Useful primarily in Vagrant and will only work on the LibreNMS server itself. Defaults to false.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'manifests/device.pp', line 39
class librenms::device
(
Boolean $manage = true,
String $librenms_basedir = '/opt/librenms',
Optional[String] $community = undef,
Optional[String] $user = undef,
Optional[String] $pass = undef,
Enum['v1','v2c','v3'] $proto = 'v3',
Boolean $realize = false
)
{
if $manage {
$basecmd = "${librenms_basedir}/addhost.php ${::fqdn}"
case $proto {
'v2c': { $params = "${community} ${proto}" }
'v3': { $params = "ap ${proto} ${user} ${pass} ${pass} sha aes" }
default: { fail("Invalid value ${proto} for parameter \$proto") }
}
$fullcmd = "${basecmd} ${params}"
$exec_defaults = {
'command' => $fullcmd,
'path' => [ $librenms_basedir, '/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', 'usr/local/sbin' ], # lint:ignore:140chars
'unless' => ["mysql --defaults-extra-file=/root/.my.cnf -e \"SELECT hostname FROM librenms.devices WHERE hostname = \'${::fqdn}\'\"|grep ${::fqdn}"], # lint:ignore:140chars
'user' => 'root',
}
# Add the node if it does not already exist in LibreNMS database. The grep
# is needed to produce a meaningful return value (0 or 1).
if $realize {
exec { "Add ${::fqdn} to librenms":
* => $exec_defaults,
}
} else {
@@exec { "Add ${::fqdn} to librenms":
tag => 'librenms-add_device',
* => $exec_defaults,
}
}
}
}
|