#!/usr/bin/perl ############################################################## # Note by Erik Ljungström: # This has not been tested by me, but I trust it's working. # Any comments/questions goes to the author below. Thanks # a million and a half for this! # # Please look through the entire script, it WILL most likely # need changing before use! # # Script: linkuptime.pl # Description: Optention des stats uptime liaison ADSL pour mrtg # # v1.0 création 21 avril 2006 par L. Mesuré # v1.1 Modifié 29 avril 2006 par L. Mesuré - Modification du mode de calcul # v2.0 Modifié 8 mai 2006 par L. Mesuré - Ajout du calcul depuis le démarrage (sans durée annoncée) # # Copyright avril-mai 2006 Laurent Mesuré sous la licence GPL # # # ICPLD is running with PID: 7857 # Connection is currently: UP # Since: Wed Mar 29 21:51:35 2006 or Since: Has not been down # Using ip: 82.238.125.254 # Using interval: 30 # Using dinterval: 30 # Logging to: /var/log/icpld/log # HTML duplicating to: /var/www/html/icpld.html use strict; use warnings; use Date::Parse; use DateTime; use DateTime::Duration; use DateTime::Format::Strptime; use Sys::Hostname; use Sys::Load qw/getload uptime/; my @status; my $dt; my $dtn; my $duree; my $analyseur; my $pid; my $d; #open COMMAND, '/usr/local/bin/icpld -status|'; my $i=0; #@status=(); @status=`/usr/local/bin/icpld -status`; my $datetext=$status[2]; if ($datetext =~ m/Since: Has not been down/) { ($pid) = ($status[0] =~ m/ICPLD is running with PID: (.*)/ ); $d=`ps -o lstart $pid | grep -v STARTED`; $analyseur = DateTime::Format::Strptime->new( pattern=> '%a %b %d %H:%M:%S %Y'); $dt = $analyseur->parse_datetime($d); } else { $analyseur = DateTime::Format::Strptime->new( pattern=> 'Since: %a %b %d %H:%M:%S %Y'); $dt = $analyseur->parse_datetime($datetext); } $dt->set_time_zone('Europe/Paris'); $dtn = DateTime->now->set_time_zone('Europe/Paris'); $duree = sprintf("%.0f",($dtn->jd - $dt->jd)*86400); if ( $status[1] =~ m/UP/) { print $duree . "\n"; print "0.0\n"; } else { print "0.0\n"; print $duree . "\n"; } print `uptime | awk -F ',' '{ print \$1 \$2 }' | sed "s,^ ,,g"`; print hostname() . "\n";