#!/opt/OV/nonOV/perl/a/bin/perl use strict; use warnings; sub safe_backticks { my ($cmd, @args) = @_; open (my $pipe, '-|', $cmd, @args) or die "Could not run $cmd @args: $!\n"; my $output = do {local $/; <$pipe>}; defined ($output) or die "read: $!"; unless( close($pipe) ) { my $error = ($? & 0x7f) ? 'Signal ' . ($? & 0x7f) : 'Exit status ' . ($? >> 8); die "$error: $cmd @args"; } return $output; } my $MON_NAME = $ARGV[0]; print $MON_NAME; # Config-Datei Initialisierung my $config = '/var/opt/OV/bin/instrumentation/webpage_check.cfg'; # Oeffne Datei zum Lesen, bei Fehler brich ab open my $fh, '<', $config or die $!; # einlesen des Config Files while( my $line = <$fh> ) { # teile Zeile an Tabulator und nimm die Elemente # Aufbau der Konfidatei: # Name des WebServers in 'FQDN' Tabulator 'ServiceID' Tabulator 'URL für wget' Tabulator 'zu matchendes pattern' Tabulator 'Kommentar' # fqdnTABsvc_idTABurlTABpatternTABcomment my ($fqdn, $svc_id, $url, $pattern, $comment) = split (/\t/, $line); # uebergib URL an wget my $content = safe_backticks('/usr/sfw/bin/wget', '-t', '2', '-T', '5', '-S', '-O', '-', $url ); # Suche des zu erwartenden pattern innerhalb des Abbilds my @foo = grep(/$pattern/, $content); if ( @foo ){ # wenn das $pattern im $content gefunden wurde, erzeuge einen Openview internen Aufruf (Wert 0 erzeugt ein Normal (grün) Event) system "/opt/OV/bin/opcmon", "$MON_NAME=0", "-object", "Webpage_Monitor", "-option", "node=$fqdn", "-option", "url=$url", "-option", "svc_id=$svc_id", "-option", "comment=$comment"; }else { # wenn das $pattern im $content nicht gefunden wurde, erzeuge einen Openview internen Aufruf (Wert 1 erzeugt ein major (orange) Event) system "/opt/OV/bin/opcmon", "$MON_NAME=1", "-object", "Webpage_Monitor", "-option", "node=$fqdn", "-option", "url=$url", "-option", "svc_id=$svc_id", "-option", "comment=$comment"; } } close $fh;