zabbix-agent-addons/zabbix_scripts/disco_sensors

42 lines
896 B
Plaintext
Raw Normal View History

2013-04-15 18:43:43 +02:00
#!/usr/bin/perl -w
use Config::Simple;
2015-07-07 14:36:59 +02:00
use Getopt::Long;
use JSON;
2015-07-07 14:36:59 +02:00
my $type = 'temp';
2015-07-07 14:36:59 +02:00
GetOptions(
"type:s" => \$type
2015-07-07 14:36:59 +02:00
);
# empty means temp
$type = ($type eq '') ? 'temp' : $type;
2015-07-07 14:36:59 +02:00
2013-04-15 18:43:43 +02:00
my $json;
@{$json->{data}} = ();
2013-04-15 18:43:43 +02:00
my $cfg = new Config::Simple;
$cfg->read('/etc/zabbix/sensors.ini');
$cfg->syntax('ini');
my %sensors = ();
2015-07-08 20:03:18 +02:00
foreach my $k (keys %{$cfg->vars}){
$k =~ s/\..*$//;
$sensors{$k} = 1 unless $sensors{$k};
}
2013-04-15 18:43:43 +02:00
foreach my $k (keys %sensors){
my $sensor = $cfg->get_block($k);
next if ($type ne 'all' && $type ne $sensor->{type});
push @{$json->{data}}, {
"{#SENSORNAME}" => $k,
"{#SENSORDESC}" => $sensor->{description},
"{#SENSORTHRESHIGH}" => $sensor->{threshold_high},
"{#SENSORTHRESLOW}" => $sensor->{threshold_low},
"{#SENSORTYPE}" => $sensor->{type},
"{#SENSORUNIT}" => $sensor->{unit}
};
2013-04-15 18:43:43 +02:00
}
print to_json($json);
2013-04-15 18:43:43 +02:00
exit(0);