use Net::SNMP;
use IO::Socket::INET;
+use IO::Select;
use RRDs;
use File::Copy;
use Data::Dumper;
return undef if (!$sock);
- chomp(my $value = <$sock>);
+ my $select = IO::Select->new($sock);
+
+ my $value = undef;
+
+ if ($select->can_read(1)) {
+ chomp($value) if (sysread($sock, $value, 4096) > 0);
+ }
close($sock);
$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);
+
+ my $select = IO::Select->new($sock);
+
+ while($select->can_read(1)) {
+ if (sysread($sock, my $buf, 16384) > 0) {
+ $buf=~s/\r//g;
+ foreach my $line (split(/\n/, $buf)) {
+ (my $key, my $value) = split(/${delimiter}/, $line);
+ $value=~ s/\s//g;
+ $values{$key} = $value;
+ }
+ } else {
+ last;
+ }
+ }
+
+ 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);
print HTML "<a href=\"${hostname}.${var}.html\"><img src=\"${hostname}.${var}.png\" width=\"${width}\" height=\"${height}\" border=\"0\"></a><br>\n";
open (HTML2, ">${outdir}/${hostname}.${var}.html.new");
- print HTML2 '<html><head><meta http-equiv="refresh" content="60"/><meta http-equiv="cache-control" content="no-cache"/><meta http-equiv="pragma" content="no-cache"/><meta http_equiv="expires" content="Sat, 26 Jul 1997 05:00:00 GMT"/><title>' . $vars->{$var}->{'name'} . '</title></head>';
+ print HTML2 '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="refresh" content="60"/><meta http-equiv="cache-control" content="no-cache"/><meta http-equiv="pragma" content="no-cache"/><meta http_equiv="expires" content="Sat, 26 Jul 1997 05:00:00 GMT"/><title>' . $vars->{$var}->{'name'} . '</title></head>';
print HTML2 '<body bgcolor="#ffffff">';
push @graphdef, "VDEF:min=${var},MINIMUM";