--- /dev/null
+package UPSGRAPH;
+
+$outdir="/var/www/klimaschrank/";
+$step=60;
+
+$hosts = [
+ {
+ 'address' => "131.188.42.24",
+ 'name' => "klimaschrank",
+ 'rrdfile' => "/var/www/klimaschrank/.work/klimaschrank.rrd",
+
+ 'fields' => [ 'kaltw', 'vorlauf', 'ruecklauf', 'abluft', 'raum' ],
+
+ 'vars' => {
+ 'kaltw' => {
+ 'name' => 'Kaltwasser',
+ 'port' => '1337',
+ 'proto' => 'tcp_multi',
+ 'multi_id' => '6328',
+ 'multi_delimiter' => " ",
+ },
+ 'vorlauf' => {
+ 'name' => 'Vorlauftemperatur',
+ 'port' => '1337',
+ 'proto' => 'tcp_multi',
+ 'multi_id' => '2d28',
+ 'multi_delimiter' => " ",
+ },
+ 'ruecklauf' => {
+ 'name' => 'Ruecklauftemperatur',
+ 'port' => '1337',
+ 'proto' => 'tcp_multi',
+ 'multi_id' => '5228',
+ 'multi_delimiter' => " ",
+ },
+ 'abluft' => {
+ 'name' => 'Ablufttemperatur',
+ 'port' => '1337',
+ 'proto' => 'tcp_multi',
+ 'multi_id' => 'f528',
+ 'multi_delimiter' => " ",
+ },
+ 'raum' => {
+ 'name' => 'Raumtemperatur',
+ 'port' => '1337',
+ 'proto' => 'tcp_multi',
+ 'multi_id' => '9028',
+ 'multi_delimiter' => " ",
+ },
+ }
+ },
+];
+
+1;
$value;
}
+sub fetch_tcp_multi(@) {
+ my $address = shift;
+ my $port = shift;
+ my $delimiter = shift;
+ my %values;
+
+ my $sock = IO::Socket::INET->new(PeerAddr => $address,
+ PeerPort => $port,
+ Proto => 'tcp',
+ Timeout => 1);
+
+ return undef if (!$sock);
+
+ while(<$sock>) {
+ chomp;
+ (my $key, my $value) = split(/${delimiter}/, $_);
+ $value=~ s/\s//g;
+ $values{$key} = $value;
+ }
+
+ close($sock);
+
+ %values;
+}
+
if ($> == 0) {
if (@ARGV != 2) {
print STDERR "Running as root, please provide UID as 2th argument!\n";
my $vars = $host->{'vars'};
my $rrdfile = $host->{'rrdfile'};
my $hostname = $host->{'name'};
+ my %multi_values = ();
foreach my $var (@{$host->{'fields'}}) {
delete $vars->{$var}->{'value'};
$result = fetch_snmp($host->{'address'}, $host->{'community'}, $vars->{$var}->{'oid'});
} elsif ($vars->{$var}->{'proto'} eq 'tcp') {
$result = fetch_tcp($host->{'address'}, $vars->{$var}->{'port'});
+ } elsif ($vars->{$var}->{'proto'} eq 'tcp_multi') {
+ if (defined($multi_values{$vars->{$var}->{'multi_id'}})) {
+ $result = $multi_values{$vars->{$var}->{'multi_id'}}
+ } else {
+ my %values = fetch_tcp_multi($host->{'address'}, $vars->{$var}->{'port'}, $vars->{$var}->{'multi_delimiter'});
+ @multi_values{keys %values} = values %values;
+ $result = $multi_values{$vars->{$var}->{'multi_id'}};
+ }
}
next unless (defined $result);