2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-15 22:26:04 +00:00

32_SYSSTAT.pm: added mibs attribute

fixed crash on unreachable snmp host
               change \ to / for windows filesystems


git-svn-id: https://svn.fhem.de/fhem/trunk@8914 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
justme-1968 2015-07-07 16:58:36 +00:00
parent 4a74b055d8
commit 600bf83e7e
2 changed files with 44 additions and 17 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
- feature: SYSSTAT: added mibs attribute for snmp monitoring
- bugfix: Dashboard: fixed CSS height issue for rows (top, center, bottom)
- feature: FB_CALLLIST: new attribute "external-mapping", new column for
external_connection reading (see commandref for details, by Michael)

View File

@ -42,7 +42,7 @@ SYSSTAT_Initialize($)
$hash->{GetFn} = "SYSSTAT_Get";
$hash->{AttrFn} = "SYSSTAT_Attr";
$hash->{AttrList} = "disable:1 disabledForIntervals raspberrycpufreq:1 raspberrytemperature:0,1,2 synologytemperature:0,1,2 stat:1 uptime:1,2 ssh_user ";
$hash->{AttrList} .= " snmp:1";
$hash->{AttrList} .= " snmp:1 mibs" if( $SYSSTAT_hasSNMP );
$hash->{AttrList} .= " filesystems showpercent";
$hash->{AttrList} .= " useregex:1" if( $SYSSTAT_hasSysStatistics );
$hash->{AttrList} .= " $readingFnAttributes";
@ -285,24 +285,27 @@ SYSSTAT_GetUpdate($)
push @snmpoids, sprintf( ".1.3.6.1.2.1.25.2.3.1.6.%i", $id );
}
my $response = SYSSTAT_readOIDs($hash,\@snmpoids);
for my $id (@{$hash->{filesystems}}) {
my $unit = $response->{sprintf( ".1.3.6.1.2.1.25.2.3.1.4.%i", $id )};
my $free = $response->{sprintf( ".1.3.6.1.2.1.25.2.3.1.5.%i", $id )} - $response->{sprintf( ".1.3.6.1.2.1.25.2.3.1.6.%i", $id )};
if( $response ) {
for my $id (@{$hash->{filesystems}}) {
my $unit = $response->{sprintf( ".1.3.6.1.2.1.25.2.3.1.4.%i", $id )};
my $free = $response->{sprintf( ".1.3.6.1.2.1.25.2.3.1.5.%i", $id )} - $response->{sprintf( ".1.3.6.1.2.1.25.2.3.1.6.%i", $id )};
if( $showpercent ) {
$free = 100 * $response->{sprintf( ".1.3.6.1.2.1.25.2.3.1.6.%i", $id )} / $response->{sprintf( ".1.3.6.1.2.1.25.2.3.1.5.%i", $id )};
$free = sprintf( "%.1f", $free );
} else {
$free *= $unit;
}
my $name = $response->{sprintf( ".1.3.6.1.2.1.25.2.3.1.3.%i", $id )};
if( $name =~ m/^([[:alpha:]]:\\)/ ) {
$name = $1
} else {
$name =~ s/ //g;
if( $showpercent ) {
$free = 100 * $response->{sprintf( ".1.3.6.1.2.1.25.2.3.1.6.%i", $id )} / $response->{sprintf( ".1.3.6.1.2.1.25.2.3.1.5.%i", $id )};
$free = sprintf( "%.1f", $free );
} else {
$free *= $unit;
}
my $name = $response->{sprintf( ".1.3.6.1.2.1.25.2.3.1.3.%i", $id )};
if( $name =~ m/^([[:alpha:]]:\\)/ ) {
$name = $1;
$name =~ s.\\./.g;
} else {
$name =~ s/ //g;
}
readingsBulkUpdate($hash,$name,$free);
}
readingsBulkUpdate($hash,$name,$free);
}
} elsif( defined($hash->{diskusage} ) ) {
@ -349,6 +352,25 @@ SYSSTAT_GetUpdate($)
}
}
if( $hash->{USE_SNMP} && defined($hash->{session}) ) {
if( my $mibs = AttrVal($name, "mibs", undef) ) {
my @snmpoids;
foreach my $entry (split(' ,', $mibs)) {
my($mib,undef) = split(':', $entry );
push @snmpoids, $mib;
}
my $response = SYSSTAT_readOIDs($hash,\@snmpoids);
foreach my $entry (split(' ,', $mibs)) {
my($mib,$reading) = split(':', $entry );
my $result = $response->{$mib};
readingsBulkUpdate($hash,$reading,$result);
}
}
}
if( AttrVal($name, "raspberrycpufreq", 0) > 0 ) {
my $freq = SYSSTAT_getPiFreq($hash);
readingsBulkUpdate($hash,"cpufreq",$freq);
@ -783,6 +805,8 @@ SYSSTAT_getStat($)
<code>attr sysstat filesystems 1,3,5</code><br>
</ul></li></lu>
<li>disabledForIntervals HH:MM-HH:MM HH:MM-HH-MM...</li>
<li>mibs<br>
space separated list of &lt;mib&gt;:&lt;reding&gt; pairs that sould be polled.</li>
<li>showpercent<br>
If set the usage is shown in percent. If not set the remaining free space in bytes is shown.</li>
<li>snmp<br>
@ -906,6 +930,8 @@ SYSSTAT_getStat($)
<code>attr sysstat filesystems /dev/.*</code><br>
<code>attr sysstat filesystems 1,3,5</code><br>
</ul></li>
<li>mibs<br>
Leerzeichen getrennte Liste aus &lt;mib&gt;:&lt;reding&gt; Paaren die abgefragt werden sollen.</li>
<li>showpercent<br>
Wenn gesetzt, wird die Nutzung in Prozent angegeben. Wenn nicht gesetzt, wird der verf&uuml;bare
Platz in Bytes angezeigt.</li>