Desarrollo de plugins de Nagios

Ejemplo de plugins SNMP

snmpd.conf

exec .1.3.6.1.4.1.2021.555.1 cat /bin/cat /backup/export_full/export_full.exit_status
exec .1.3.6.1.4.1.2021.555.2 cat /bin/cat /backup/export_dos/export_dos.exit_status
exec .1.3.6.1.4.1.2021.555.3 cat /bin/cat /backup/export_full_DB/export_full_DB.exit_status
exec .1.3.6.1.4.1.2021.555.4 cat /bin/cat /backup/export_tres/exportTRES.exit_status

<file perl check_snmp_exit_status.pl> #!/usr/bin/perl use Net::SNMP; $oid = $ARGV[1];

$snmpv3_username = “nagios”; # SNMPv3 username $snmpv3_password = “ClaV3RfsTtD2”; # SNMPv3 password $snmpv3_authprotocol = “md5”; # SNMPv3 hash algorithm (md5 / sha) $snmpv3_privpassword = “”; # SNMPv3 hash algorithm (md5 / sha) $snmpv3_privprotocol = “des”; # SNMPv3 encryption protocol (des / aes / aes128) $version = “3”; $timeout = “2”; $hostname = $ARGV[0]; # Crear la sesion SNMP

($s, $e) = Net::SNMP->session(
-username => $snmpv3_username,
-authpassword => $snmpv3_password,
-authprotocol => $snmpv3_authprotocol,
-hostname => $hostname,
-version => $version,
-timeout => $timeout,
);
if ($s){
} else {
print "CRITICAL - El agente no responde, SNMP v3 ($e)\n";
exit(2);
}
$s->get_request($oid);
foreach ($s->var_bind_names()) {
$oid_consulta = $s->var_bind_list()->{$_};
}

$s→close();

if($oid_consulta == 0) {

print "OK - El exit status es ".$oid_consulta."\n";
exit 0;

} else {

print "CRITICAL - El exit status es ".$oid_consulta."\n";
exit 2;

} </code>