Script need help



Hi!!!
I have written this script (see below) to check when the server or database is not running...but I can not seem to work around the error it is giving. The result it gave me is:
"Website is up and running
Can't connect to data source"


#!/usr/bin/perl
use strict;
use LWP::UserAgent;
use DBI;
use Net::Ping;
use MIME::Lite;

my $is_httpd_ok = &check_httpd();
my $is_db_ok = &check_database();
my $is_chat_ok = &check_chat();
my $is_prsd_ok = &check_prsd();
# if any one is not ok then send an email
if ( (!$is_httpd_ok) || (!$is_db_ok) || (!$is_chat_ok) || (!$is_prsd_ok) ) {
# use MIME::Lite to send an email.


my $msg = MIME::Lite->new(
From =>'server@xxxxxxxxxxx',
To =>'person@xxxxxxxxxxx',
Subject =>"Server error report",
Type => 'text',
Data =>"Server error report for scalar(localtime()), - " . time(), #timestamp??
);
# also add record to monitor.log that email was sent
$msg->send();

open (FILE, ">>monitor.log");
print FILE "This is a test\n";
close (FILE);

}
exit();
# if httpd is up, then status return should be TRUE
sub check_httpd {
# use LWP to check www.example.com
my $ua = LWP::UserAgent->new();
my $request = HTTP::Request->new('GET', 'http://www.example.com');
my $response = $ua->request($request);


# if database is up, then status return should be TRUE
if ($response->is_success()) {
# This should eventually be logged - open FILE (">>monitor.log") || die "some error";
print "Website is up and running\n";
}
else {
# This should eventually be logged - open FILE (">>monitor.log") || die "some error";
print "Website is down\n";
return 0;
}
return 1;
}


sub check_database {
# use dbi to check anne (DBI->ping())
my $dbh = DBI->connect() #need to rectify error message problem
or die "Cannot connect to database! Error found: $DBI::errstr";
$dbh->ping();


# my $dbh;
# eval {
# alarm(5); # seconds before time out
# $dbh = DBI->connect("dbi:Oracle:$dsn" ... );
# alarm(0); # cancel alarm (if connect worked fast)
# };
# alarm(0); # cancel alarm (if eval failed)

# return status of running database

if ($dbh-> is_success())
{
warn "database is up";

}
else
{
warn 'database is not connected [$ping_val]\n';
}

# if chat is up, then status return should be TRUE
sub check_chat {


# use net ping to check emily on port 4674
}
sub check_prsd {


# use net ping to check emily on port 2323

}
}



---------------------------------
Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great rates starting at 1¢/min.

Relevant Pages

  • Re: What is the name of the Language we are using & recommend book
    ... Can I have 2 sub forms in a form that are not sub forms of the other sub ... As for my process I am trying to create my Access Database in shells like ... QSL or Microsoft SQL Server Data Engine or what. ... language of queries, and the query design grid is just a tool to construct ...
    (microsoft.public.access.formscoding)
  • Re: Custom Login Screen
    ... Private Sub cmdLogin_Click ... On Error GoTo ErrorHandler ... You will need to enter your full path to the database file and MDW file in the appropriate places. ... Now make an MDE file from this MDB. ...
    (microsoft.public.access.security)
  • Re: Jeff C
    ... properly secure an Access database. ... Private Sub Form_Open ... Resume ExitPoint ... Dim db As DAO.Database ...
    (microsoft.public.access.formscoding)
  • Re: How to use a logon screen to log into a secured Database?
    ... > that appears with a secured database. ... >>On Error GoTo ErrorHandler ... >> Exit Sub ... Now make an MDE file ...
    (microsoft.public.access.security)
  • Re: linking databases
    ... Doug Steele, Microsoft Access MVP ... Sub chrCountry_AfterUpdatestring highlighted in yellow.The code as I ... I using the text box's [Event Procedure] After Update property on the ... The name of the column in the table in the 2nd database I want to ...
    (microsoft.public.access.externaldata)