#!/usr/bin/perl -w use JSON; use Getopt::Long; my $sensor_type = 'temp'; GetOptions( "type:s" => \$sensor_type ); # empty means temp $sensor_type = ($sensor_type eq '') ? 'temp' : $sensor_type; my $json; @{$json->{data}} = (); open SENSORS, ('){ next unless (/^(\w+)(\s+)?=(\s+)?(.*)!(\-?\d+)!(\-?\d+)(!(\w+))?$/); my ($sensor,$threshigh,$threslow,$type) = ($1,$5,$6,$8); $type ||= 'temp'; next if ($sensor_type ne 'all' && $type ne $sensor_type); push @{$json->{data}}, { "{#SENSORNAME}" => $sensor, "{#SENSORTHRESHIGH}" => $threshigh, "{#SENSORTHRESLOW}" => $threslow, "{#SENSORTYPE}" => $type }; } close SENSORS; print to_json($json); exit(0);