/[rrd-simple-monitoring]/bin/rrd-client-infrant.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /bin/rrd-client-infrant.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Thu Jul 16 18:48:19 2009 UTC (12 years, 3 months ago) by dpavlin
File MIME type: text/plain
File size: 2793 byte(s)
import upstream http://rrd.me.uk/rrd-simple-monitoring.tar.gz

without prerequisities

1 #!/usr/bin/perl -w
2
3 use 5.6.1;
4 use strict;
5 use warnings;
6 use LWP::UserAgent qw();
7 use HTML::TokeParser qw();
8 use HTTP::Request::Common qw();
9
10 use constant USER => 'admin';
11 use constant PASS => 'password';
12 use constant REALM => 'Control Panel';
13 use constant NETLOC => '192.168.0.2:443';
14 use constant URL => 'https://'.NETLOC.'/admin/index.cgi?button=Current&MODIFIED=0&CURRENTPAGE=Status&CURRENTTAB=health&DEBUGLEVEL=0&command=Refresh&MODE=Advanced';
15 use constant RRDURL => 'http://rrd.me.uk/cgi-bin/rrd-server.cgi';
16
17 my $ua = LWP::UserAgent->new;
18 $ua->timeout(10);
19 $ua->credentials(NETLOC, REALM, USER, PASS);
20 my $response = $ua->get(URL);
21 die $response->status_line unless $response->is_success;
22
23 my $p = HTML::TokeParser->new(\$response->content);
24 my %update = ();
25 my $time = time;
26
27 while (my $token = $p->get_tag('tr')) {
28 my $text = $p->get_trimmed_text('/tr');
29 $text =~ s/[^a-zA-Z0-9\.\-\_\%\/\\]/ /g;
30 if ($text =~ /\b((Disk|Fan|Temp|UPS)(?:\s+([0-9]+)\b)?.+)/) {
31 my ($type,$num) = ($2,$3);
32 local $_ = $1;
33
34 if ($type eq 'Disk' || $type eq 'Temp') {
35 if (/\s(([0-9\.]+)\s*C)\s/) { $update{"hdd.temp.c"}->{"${type}_${num}_C"} = $2; }
36 if (/\s(([0-9\.]+)\s*F)\s/) { $update{"hdd.temp.f"}->{"${type}_${num}_F"} = $2; }
37 }
38
39 if ($type eq 'Fan' && /\s(([0-9\.]+)\s*RPM)\s/) { $update{"misc.fan.rpm"}->{"${type}_${num}_RPM"} = $2; }
40 }
41 }
42
43
44 while (my ($graph,$ref) = each %update) {
45 my $data = '';
46 while (my ($key,$value) = each %{$ref}) {
47 $data .= "$time.$graph.$key $value\n"
48 }
49 update($data);
50 }
51
52
53 exit;
54
55
56 sub update {
57 my $data = shift;
58
59 my $ua = LWP::UserAgent->new(agent => $0);
60 my $resp = $ua->request(HTTP::Request::Common::POST(RRDURL,
61 Content_Type => 'text/plain',
62 Content => $data
63 ));
64
65 if ($resp->is_success) {
66 printf("%s\n",$resp->content);
67 } else {
68 warn 'Posting Error: '.$resp->status_line;
69 }
70
71 return $resp->is_success;
72 }
73
74
75 __END__
76 nicolaw@eowyn:~$ wget -q -O - --no-check-certificate --http-user=admin --http-password=password "https://192.168.0.2/admin/index.cgi?button=Current&MODIFIED=0&CURRENTPAGE=Status&CURRENTTAB=health&DEBUGLEVEL=0&command=Refresh&MODE=Advanced" | html2text -width 300 | egrep -io " (Disk|Fan|Temp|UPS) [0-9] .*"
77 Disk 1 Seagate ST3500630AS 465 GB, 40C / 104F, Write-cache ON, SMART+ OK
78 Disk 2 Seagate ST3500630AS 465 GB, 41C / 105F, Write-cache ON, SMART+ OK
79 Disk 3 Seagate ST3500630AS 465 GB, 41C / 105F, Write-cache ON, SMART+ OK
80 Disk 4 Seagate ST3500630AS 465 GB, 39C / 102F, Write-cache ON, SMART+ OK
81 Fan 1 1744 RPM [Unknown INPUT type] OK
82 Temp 1 34.0C / 93F [Normal 0-60C / 32-140F] OK
83 UPS 1 Not present OK
84 nicolaw@eowyn:~$
85

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26