#!/usr/bin/perl -ws # # $Id: uptime-chaos.pl,v 1.3 2003/04/30 15:59:45 agramajo Exp $ # # uptime-chaos.pl - UptimeChaos 0.1.2 # perl uptime client, only protocol version 5 # # authkey|uptime|load|idle|os|oslevel|cpu|client # http://uptimes.wonko.com/protocol.php # # Alejandro Gramajo # # see changelog.txt # ################################################### # C O N F I G U R A T I O N ################################################### # required auth key for your host my $authkey = $key || ""; my $interval = 5; # secs for idle calc my $showidle = 1; # 0 -> idle not send my $showload = 1; # 0 -> load not send # uptime server my $server = "uptimes.hostingwired.com"; my $port = 49153; # where bins? my $binvmstat = "/usr/bin/vmstat"; my $binuptime = "/usr/bin/uptime"; # works on Linux, Solaris and FreeBSD my ($os, $oslevel, $cpu) = (split /\s+/, `uname -smr`); my $client = "UptimeChaos/0.1.2"; # 1 for debug and not send packet my $showdebug = $debug || 0; ################################################### # M A I N ################################################### use IO::Socket; use strict; use vars qw($debug $key); die "auth required, look source!" unless $authkey; my (@stat,$temp,$idle,$load,$uptime,$packet,$sock); my ($dd,$hh,$mm) = (0,0,0); if ($showidle || $showload) { open(INPUT,"$binvmstat $interval 2|"); @stat = (); } if ($showidle) { $idle = (split /\s+/,$stat[$#stat])[-1]; } else { $idle = ""; } $temp = `$binuptime`; print $temp if $showdebug; $temp =~ s/,//g; @stat = (split /\s+/, $temp); if ($showload) { chomp($stat[-2]); $load = $stat[-2]; if ($load < 1) { $load *= 100; } elsif ($load >= 1) { $load = 100; } } else { $load = ""; } if ($temp =~ /up.*?(\d+)\s+day/) { $dd = $1; print "$dd (day)\n" if $showdebug; } if ($temp =~ /up.*?(\d+):(\d+)/) { $hh = $1; $mm = $2; print "$hh:$mm (hrs:min)\n" if $showdebug; } if ($temp =~ /up.*?(\d+)\s+min/) { $mm = $1; print "$mm (min)\n" if $showdebug; } if ($temp =~ /up.*?(\d+)\s+hrs/) { $hh = $1; print "$hh (hrs)\n" if $showdebug; } $uptime = $dd * 1440 + $hh * 60 + $mm; $packet = "$authkey|$uptime|$load|$idle|$os|$oslevel|$cpu|$client"; $sock = IO::Socket::INET->new ( PeerAddr => $server, PeerPort => $port, Proto => 'udp' ) or die "socket: $@"; if ($showdebug) { print time, " $packet\n"; } else { $sock->send($packet); } # end