#! /usr/pkg/bin/perl # preparation of tivo data for mrtg # Scott Presnell, srp@tworoads.net, Wed Jan 2 08:15:22 PST 2002 # $Id: tivoprep,v 1.3 2004/02/10 16:23:19 srp Exp srp $ use LWP; #Local storage directory $workdir = "/usr/local/etc"; # TiVo loadavg $avfile = ".tivoav"; $avpath = join("/", $workdir, $avfile); # TiVo Temp file. $tmfile = ".tivotm"; $tmpath = join("/", $workdir, $tmfile); # TiVo hours file. $hrfile = ".tivohr"; $hrpath = join("/", $workdir, $hrfile); # $opt_d = 1; my $ua = new LWP::UserAgent; $ua->agent("tivoprep/1.0 " . $ua->agent); # Create a request my $requrl = join("/", "http:", "", "", "info"); my $req = new HTTP::Request GET => $requrl; $req->content_type('application/x-www-form-urlencoded'); # Pass request to the user agent and get a response back my $res = $ua->request($req); $stage = 0; # Check the outcome of the response if ($res->is_success) { @ulines = split('\r\n', $res->content); foreach (@ulines) { # # print STDERR "line: \"$_\"\n"; if (/^(.*)<\/td>(.*)<\/td><\/tr>/i) { $key = $1; $val = $2; $key =~ s/ \;/ /; $key =~ s/\://; $info{$key} = $val; # print "Key: $key, Val: $val\n"; } if (/^(.*)<\/nobr><\/td>/) { $stage = 1; $key = $1; } if (/^(.*)<\/td>/) { $space{$key}{$stage} = $1; $stage++; } } } my ($l) = $info{'Load Average'}; $five = int($l * 100); print "loadave: ($l)", $five, "\n" if ($opt_d); my ($t) = $info{'Current Temperature'}; $t =~ s/(\d\d)C/$1/g; $t = int(($t * 1.8) + 32.5); print "t: ", $t, "\n" if ($opt_d); my ($u) = $info{'Uptime'}; if ($u =~ /(\d+)d\s(\d+)h\s(\d+)m\s(\d+)s/) { $day = $1; $hour = $2; $min = $3; $sec = $4; $uptime = sprintf("%d days, %02d:%02d", $day, $hour, $min); print "uptime: ", $uptime, "\n" if ($opt_d); } my ($h) = $space{'Total'}{4}; if ($h =~ /(\d+)\:(\d+)\:(\d+)/) { $total = int($1 + $2/60 + 0.5); print "total: ", $total, "\n" if ($opt_d); } my ($d) = $space{'Deleted'}{4}; if ($d =~ /(\d+)\:(\d+)\:(\d+)/) { $deleted = int ($1 + $2/60 + 0.5); print "deleted: ", $deleted, "\n" if ($opt_d); } if (open(AV, "> $avpath")) { print AV $five, "\n"; print AV $five, "\n"; print AV $uptime, "\n"; print AV "TiVo PTVR\n"; close(AV); } if (open(TM, "> $tmpath")) { print TM $t, "\n"; print TM $t, "\n"; print TM $uptime, "\n"; print TM "TiVo PTVR\n"; close(TM); } if (open(HR, "> $hrpath")) { print HR $deleted, "\n"; # green print HR $total, "\n"; # blue print HR $uptime, "\n"; print HR "TiVo PTVR\n"; close(HR); } exit(0);
Scott Presnell
Last modified: Monday, February 16, 2004 11:27 PST