Operating System - Linux
1828790 Members
2637 Online
109985 Solutions
New Discussion

how generate an event when only an interface become down after N minutes ?

 
SOLVED
Go to solution
marouanej
Occasional Advisor

how generate an event when only an interface become down after N minutes ?

I have configured perl script that send me an email event whenever a stat of a managed router interface become DOWN or UP.
to avoide receiving a lot of email alert due interface reset.
how to make the event generated only when an interface is down for exemple at least for 3 minutes?

many Thanks
12 REPLIES 12
Ivan Ferreira
Honored Contributor

Re: how generate an event when only an interface become down after N minutes ?

You could create a "lock" file to identify that the mail already was sent. for example:

if interface down then
check if lock file exists
if lock file does not exists
create lock file
send email alert
if lock file exists
do nothing
fi
fi
if interface up then
remove lock file
send email notification
fi
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Alexander Chuzhoy
Honored Contributor

Re: how generate an event when only an interface become down after N minutes ?

You can use "threads" functionality.
So as soon as your interface goes down.
Another thread starts and counts the time (3 minutes in your example).
Upon this thread's closure-the parent will generate an email...
Hope it helps.

P.S.
How do you monitor the router's interface - just curious.
marouanej
Occasional Advisor

Re: how generate an event when only an interface become down after N minutes ?



I have made a script tha combine the two suggestions
lockfile and sleep fonction

it work now :-)

thank you
Ivan Ferreira
Honored Contributor
Solution

Re: how generate an event when only an interface become down after N minutes ?

Good marouanej and welcome to the forum.

Please see also:

http://forums1.itrc.hp.com/service/forums/helptips.do?#28
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
marouanej
Occasional Advisor

Re: how generate an event when only an interface become down after N minutes ?

i have created thoses two scripts
the first one is executed when for exemple an interface goes down and the seconde when it become up:

=================================================
when interface goes down this script is executed
================================================
#!/opt/OV/bin/Perl/bin/perl


my $arg = $ARGV[0];
my @indexe = (2, 3, 9, 10, 11, 25);

if($arg == $indexe[0])
{
system("touch lockfile");
sleep 10;
$file = 'lockfile';
if(-e $file)
{
#if file existe send mail to toto
system "/opt/OV/bin/sendmail 'inteface is Down' toto@";
exec "rm lockfile";
}
}

==============================================
when interface become up this script is executed
===============================================

#!/opt/OV/bin/Perl/bin/perl


my $arg = $ARGV[0];
my @indexe = (2, 3, 9, 10, 11, 25);

if($arg == $indexe[0])
{
$file = 'lockfile';
if(-e $file)
{
exec "rm lockfile";
}
else{
system("/opt/OV/bin/sendmail 'interface is up' toto@");
}
}
===============================
when i execute the script at the unix command line the lockfile is created . but when i shutdown the interface evenif the lockfile is not created i receive "interface is down "email notification.


many thanks
Alexander Chuzhoy
Honored Contributor

Re: how generate an event when only an interface become down after N minutes ?

Jul 18, 2006 12:23:14 GMT N/A: Question Author

--------------------------------------------------------------------------------
i have created thoses two scripts
the first one is executed when for exemple an interface goes down and the seconde when it become up:

=================================================
when interface goes down this script is executed
================================================
#!/opt/OV/bin/Perl/bin/perl


my $arg = $ARGV[0];
my @indexe = (2, 3, 9, 10, 11, 25);
Hm,
assigning points to all responds will be nice...
From your code it looks like if the argument to the script is "2"; then create the file ; then check if the file exists (of course it will exist -you created it); then send e-mail.

if($arg == $index[0])
{
system("touch lockfile");
sleep 10;
$file = 'lockfile';
if(-e $file)
{
#if file existe send mail to toto
system "/opt/OV/bin/sendmail 'inteface is Down' toto@";
exec "rm lockfile";
}
}
Alexander Chuzhoy
Honored Contributor

Re: how generate an event when only an interface become down after N minutes ?

1. check if rm is alias to rm -i
2. try to increase the sleep time from 10 to 30 (for test purposes).
marouanej
Occasional Advisor

Re: how generate an event when only an interface become down after N minutes ?



how to specify the path for the created lockfile ?
or
without specifying the path where the lockfile is created?
Alexander Chuzhoy
Honored Contributor

Re: how generate an event when only an interface become down after N minutes ?

without specifying the path the lockfile is created in the current directory.
Specifying lockfile with path is very simple:

$lockfile="/tmp/lockfile";

marouanej
Occasional Advisor

Re: how generate an event when only an interface become down after N minutes ?

can I test the lockfile with the path?

..
$lockfile="/opt/OV/bin/lockfile";
system "touch $lockfile";
sleep 30;
if(-e $file)
..

Alexander Chuzhoy
Honored Contributor

Re: how generate an event when only an interface become down after N minutes ?

in your last example $lockfile was the variable name, so it should be:
if ( -e $lockfile) {
"some expression";
}
marouanej
Occasional Advisor

Re: how generate an event when only an interface become down after N minutes ?

excuse me for been late to response you.
but the problem remain:
the first script create the file but the seconde doesn't delete the created file:
i'm sure that the first script is executed first but the second script wait until the first script terminate.
evenif the the time between the two stats (Down &UP) is enough lower than 160second.
logup*(see the script) containe always this error:
rm: /opt/OV/bin/lockfile non-existent
-------
_______________________________________
Script_DOWN
_______________________________________

.
.
if($arg == $indexe[0])
{
$lockfile="/opt/OV/bin/lockfile";
system "touch $lockfile";
sleep 150;
if(-e $lockfile)
{
system "/opt/OV/bin/sendmail 'Interface Down' toto@st.com";
exec "rm $lockfile > /opt/OV/bin/lockdown 2>&1";
}else
}
.
.
_________________________________________
Script_UP
_______________________________________

#!/opt/OV/bin/Perl/bin/perl
#!/bin/sh

.
.

if($arg == $indexe[0])
{
$lockfile="/opt/OV/bin/lockfile";
if(-e $lockfile){
exec "rm $lockfile > /opt/OV/bin/lockup 2>&1";
}
else{
system "/opt/OV/bin/sendmail 'Interface Down' toto@st.com";
}
}
else
{}
.
.