Thread Serverüberwachung
(15 answers)
Opened by bianca at 2010-10-20 09:27
http://www.server-module.com/
Das soll keine Empfehlung sein, ist mir aber gerade spontan eingefallen, da es genau zu deinen Anforderungen passt. EDIT: Hab gerade noch ein altes Script gefunden: Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 #!/usr/bin/perl my @url_list = qw(http://www.xxxxx.de/ http://www.xxxxx.info/); my $sleep_minutes = 1; my $send_adress = 'webservice@xxxxxxx.de'; my $notiy_adress_1 = 'office@xxxxxxxxx.de'; my $notiy_adress_2 = 'me@xxxxxxxxxxx.de'; my $mail_prog = '/usr/sbin/sendmail -t'; my $base_dir = '/home/xxxxxx/xxxxxxx'; #------------------ Run as daemon ---------------------------------# #use Proc::Daemon; #Proc::Daemon::Init; #------------------------------------------------------------------# use strict; #use warnings; #use diagnostics; use LWP; use LWP::UserAgent; use Storable qw(lock_store lock_retrieve); use File::Spec; use FindBin; sub send_notify_mail($$); sub _get_file($); my $emacs_neeed_this = {}; my $work_dir = $FindBin::Bin; while(1){ foreach my $url(@url_list){ my $ua = LWP::UserAgent->new(); $ua->agent("Server-Control/0.1, powered by KFSW"); $ua->timeout(15); my $req = HTTP::Request->new(GET => $url); my $res = $ua->request($req); my $file = _get_file($url); my $data; if(-f $file){ $data = lock_retrieve($file); }else{ $data = {}; $data->{'status'} = 'offline'; $data->{'off_notified'} = 'no'; $data->{'on_notified'} = 'no'; $data->{'time'} = time(); } if($res->is_success){ $data->{'status'} = 'online'; $data->{'time'} = time(); unless($data->{'on_notified'} eq 'yes'){ my $res = send_notify_mail($url,'online'); if($res){ $data->{'on_notified'} = 'yes'; $data->{'off_notified'} = 'no'; } } print "$url Still running \n"; }else{ unless($data->{'off_notified'} eq 'yes'){ my $res = send_notify_mail($url,'offline'); if($res){ $data->{'off_notified'} = 'yes'; $data->{'on_notified'} = 'no'; } } $data->{'status'} = 'offline'; $data->{'time'} = time(); print "$url NOT running \n" . $res->status_line . "\n"; } lock_store($data,$file); } sleep ($sleep_minutes * 60); } sub _get_file($){ my $url = shift; $url =~ s/[^a-z0-9]/_/g; my $file = File::Spec->catfile($base_dir,'memory',$url); return $file; } sub send_notify_mail($$){ my $url = shift; my $status = shift; my $mail = 'From: ' . $send_adress . "\n"; $mail .= 'To: ' . $notiy_adress_1 . "\n"; $mail .= 'Cc: ' . $notiy_adress_2 . "\n"; $mail .= 'Return-Path: ' . $send_adress . "\n"; $mail .= 'Reply-To: ' . $send_adress . "\n"; $mail .= 'Errors-To: ' . $send_adress . "\n"; $mail .= 'Subject: ' . $url . " is $status \n\n"; $mail .= 'Hello!' . "\n\n"; $mail .= 'Date ' . scalar(gmtime()) . "GMT \n"; $mail .= 'The HTTP-Server on ' . $url . " is " . $status . "\n\n"; open(MAIL,"|$mail_prog") or die("open (MAIL,\"|$mail_prog\") failed\n $! \n"); print MAIL "$mail\n"; close(MAIL) or die("close(MAIL) failed\n $! \n"); return 1; } Hat im "Hausgebrauch" gut funktioniert ;-) Last edited: 2010-10-20 09:52:19 +0200 (CEST) |