Welcome to OracleGiants.com!     

Oracle 10g DBA & Business Intelligence Resources.

Articles Scripts About Search Links
 

OraMon

This Oracle Monitoring script was written as a collaborative effort between an Oracle Certified Professional and a software engineer at the University of Akron.

This open source code is provided as-is, but we are looking for ways to continually improve upon it.

Please email any bugs/improvements to editor@oraclegiants.com

To run the monitoring code use the following command:

perl oramon.pl -h 127.0.0.1:1521 -f 10

#!/usr/bin/perl

use strict;
use warnings;
use Net::Ping;
use DBI;
use LWP::UserAgent;
use Net::FTP;
use IO::Socket;
use Net::POP3;
use Getopt::Long;
use Mail::Sendmail;
use Sys::Hostname;

my $VERSION = "3.01";
my $EMAIL_FROM = "system\@oraclegiants.com";
my $EMAIL_TO1 = "editor\@oraclegiants.com";
my $EMAIL_TO2 = "dba_manager\@oraclegiants.com";

my $FREQUENCY_TO_CHECK = "";
my $HOST_AND_PORT = "";
my %Config;

Configure( \%Config );

if (($Config{help}) || ($HOST_AND_PORT eq '')) {
Syntax();
exit();
}

my $myhost = hostname;

sub Configure {
my( $Config ) = @_;
my $Result;
Getopt::Long::Configure( "prefix_pattern=(-|\/)" );
$Result = GetOptions( $Config,
"h=s"=>\$HOST_AND_PORT,
"f=s"=>\$FREQUENCY_TO_CHECK,
"help|?"
);

$Config->{help} = 1 unless( $Result );
}

sub sendEmailAlert {

my $message = $_[0];
my $host = $_[1];
my $sService = $_[2];

my $to1 = $EMAIL_TO1;
if ($to1 ne '') {
my $to2 = $EMAIL_TO2;
my $to = $to1 . ';' . $to2;
#print "to: $to\n";

#$to =~ s/@/\\@/g;

my %mail = ( To => $to,
From => $EMAIL_FROM,
Subject => $host,
Message => $message
);
$mail{smtp} = 'smtp-server';
sendmail(%mail) or die $Mail::Sendmail::error;
print "OK. Log says:\n", $Mail::Sendmail::log, "\n";
}
}

sub tcpHost (@) {
#**********************************************
# Connect to a TCP socket/port for each of the
# hosts provided in the passed in array
#**********************************************
my @host_array = @_;
my $timeout = 10;
my $sService = "SOCKET";
my $hostPool;
my $host;

foreach $host (@host_array) {
my $tcp = IO::Socket::INET->new(
Proto => 'tcp', # protocol
PeerAddr=> $host, # Address of server and port
Reuse => 1,
Timeout => $timeout);
if ($tcp) {
#$tcp->autoflush(1); # Send immediately
registerSuccess($sService, $host);
close $tcp; # Close socket
} else {
registerFailure($sService, $host);
}
}
}
sub registerSuccess() {
my $sService = $_[0];
my $host = $_[1];

print "\n$host is reachable";
#update timestamp in database
sendEmailAlert("Host: $host Service: $sService is reachable.", $host, $sService);
}

sub registerFailure() {
my $sService = $_[0];
my $host = $_[1];

sendEmailAlert("Host: $host Service: $sService is unreachable (confirmed from 2 sources).", $host, $sService);
}

sub Syntax {
my( $Script ) = ( $0 =~ m#([^\\/]+)$# );
my $Line = "-" x length( $Script );
print STDERR << "EOT";

$Script
$Line
Monitors network services for availablity.
Version: $VERSION
Syntax: $0 [-h HOST_AND_PORT]
-h HOST_AND_PORT..........hostname/ip and port
-f FREQUENCY..............frequency in seconds to check
Examples:
perl $0 -h 127.0.0.1:1521 -f 5

EOT
}

#***************************************
# Main - call functions to perform tests
#***************************************
print "Starting application...";

while (1 == 1){

#Test - Oracle service
print "\n\n ### Oracle Port Check ###";
my @hostList;
unshift(@hostList, $HOST_AND_PORT);
tcpHost (@hostList);
sleep $FREQUENCY_TO_CHECK;

}
#***************************************
# End Main
#***************************************

Recent Posts

We are currently paying for accepted Oracle 10g DBA & Business Intelligence articles, scripts, tips & tricks. Send yours to the editor and we will review within three weeks.

Learn more

Editorial submissions & questions: editor@oraclegiants.com

 

 

This site is moderated by an:
Oracle Certified Professional
Oracle ACE

 

   Internet Child Safety   |   Internet Startups   |   Free Links
2006 OracleGiants.com