Move UPS detection in a module

tags/zabbix-agent-addons-0.2.20-1
Daniel Berteaud 10 years ago
parent f5a7ebdfed
commit f426903cc8
  1. 18
      lib/Zabbix/Agent/Addons/UPS.pm
  2. 8
      zabbix_scripts/disco_nut_ups

@ -0,0 +1,18 @@
package Zabbix::Agent::Addons::UPS;
use warnings;
use strict;
use File::Which;
# List configured UPS (only nut is supported)
sub list_ups {
my @ups = ();
my $upsc = which('upsc');
if ($upsc && -x $upsc){
my @out = qx($upsc -l);
if ($? == 0){
@ups = @out;
}
}
return @ups;
};

@ -1,15 +1,13 @@
#!/usr/bin/perl -w
use JSON;
use Zabbix::Agent::Addons::UPS;
my $json;
@{$json->{data}} = ();
if (system("upsc -l >/dev/null 2>&1") == 0){
foreach my $ups (`upsc -l`){
chomp($ups);
push @{$json->{data}}, {"{#UPSNAME}" => $ups};
}
foreach my $ups (Zabbix::Agent::Addons::UPS::list_ups()){
push @{$json->{data}}, {"{#UPSNAME}" => $ups};
}
print to_json($json);
exit(0);

Loading…
Cancel
Save