parent
f5a7ebdfed
commit
f426903cc8
2 changed files with 21 additions and 5 deletions
@ -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 |
#!/usr/bin/perl -w |
||||||
|
|
||||||
use JSON; |
use JSON; |
||||||
|
use Zabbix::Agent::Addons::UPS; |
||||||
|
|
||||||
my $json; |
my $json; |
||||||
@{$json->{data}} = (); |
@{$json->{data}} = (); |
||||||
|
|
||||||
if (system("upsc -l >/dev/null 2>&1") == 0){ |
foreach my $ups (Zabbix::Agent::Addons::UPS::list_ups()){ |
||||||
foreach my $ups (`upsc -l`){ |
|
||||||
chomp($ups); |
|
||||||
push @{$json->{data}}, {"{#UPSNAME}" => $ups}; |
push @{$json->{data}}, {"{#UPSNAME}" => $ups}; |
||||||
} |
} |
||||||
} |
|
||||||
print to_json($json); |
print to_json($json); |
||||||
exit(0); |
exit(0); |
||||||
|
Loading…
Reference in new issue