-
-
Save ashraf-s9s/6a1cf8fa3965a3930434447314e38d61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use NetSNMP::agent (':all'); | |
use NetSNMP::ASN (':all'); | |
use Time::Local; | |
my $OID = ".1.3.6.1.4.1.57397.1"; # clustercontrolMIB | |
sub myhandler { | |
my ($handler, $registration_info, $request_info, $requests) = @_; | |
my $request; | |
for($request = $requests; $request; $request = $request->next()) { | |
my $oid = $request->getOID(); | |
my $clusterId = 23; # cluster ID that you want to monitor | |
my $totalAlarm = `/bin/s9s alarms --list --cluster-id=$clusterId --batch | wc -l`; | |
my $criticalAlarm = `/bin/s9s alarms --list --cluster-id=$clusterId --batch | grep CRITICAL | wc -l`; | |
my $warningAlarm = `/bin/s9s alarms --list --cluster-id=$clusterId --batch | grep WARNING | wc -l`; | |
if ($request_info->getMode() == MODE_GET) { | |
# ... generally, you would calculate value from oid | |
if ($oid == new NetSNMP::OID($OID . ".1.1.1")) { | |
$request->setValue(ASN_INTEGER, $totalAlarm); | |
} | |
elsif ($oid == new NetSNMP::OID($OID . ".1.1.2")) { | |
$request->setValue(ASN_INTEGER, $criticalAlarm); | |
} | |
elsif ($oid == new NetSNMP::OID($OID . ".1.1.3")) { | |
$request->setValue(ASN_INTEGER, $warningAlarm); | |
} | |
elsif ($oid == new NetSNMP::OID($OID . ".1.1.4")) { | |
$request->setValue(ASN_INTEGER, $clusterId); | |
} | |
} elsif ($request_info->getMode() == MODE_GETNEXT) { | |
if ($oid == new NetSNMP::OID($OID . ".1.1.1")) { | |
$request->setOID($OID . ".1.1.2"); | |
$request->setValue(ASN_INTEGER, $criticalAlarm); | |
} | |
elsif ($oid == new NetSNMP::OID($OID . ".1.1.2")) { | |
$request->setOID($OID . ".1.1.3"); | |
$request->setValue(ASN_INTEGER, $warningAlarm); | |
} | |
elsif ($oid == new NetSNMP::OID($OID . ".1.1.3")) { | |
$request->setOID($OID . ".1.1.4"); | |
$request->setValue(ASN_INTEGER, $clusterId); | |
} | |
elsif ($oid < new NetSNMP::OID($OID . ".1.1.1")) { | |
$request->setOID($OID . ".1.1.1"); | |
$request->setValue(ASN_INTEGER, $totalAlarm); | |
} | |
} elsif ($request_info->getMode() == MODE_SET_RESERVE1) { | |
if ($oid != new NetSNMP::OID($OID . "1.1")) { # do error checking here | |
$request->setError($request_info, SNMP_ERR_NOSUCHNAME); | |
} | |
} elsif ($request_info->getMode() == MODE_SET_ACTION) { | |
# ... (or use the value) | |
$value = $request->getValue(); | |
} | |
} | |
} | |
my $agent = new NetSNMP::agent( | |
'Name' => "clustercontrol_snmp_agent", | |
'AgentX' => 1 | |
); | |
$agent->register("clustercontrol_snmp_agent", ".1.3.6.1.4.1.57397.1", | |
\&myhandler); | |
my $running = 1; | |
while($running) { | |
$agent->agent_check_and_process(1); | |
} | |
$agent->shutdown(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment