LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-05-2012, 09:20 AM   #1
ankitpandey
Member
 
Registered: Jan 2012
Location: Mumbai
Posts: 63

Rep: Reputation: Disabled
Alerting for specified condition


Hello All,

I have created one script to send me alert mail when the run time of "particular process" goes beyond defined limit. How can i automate this, i mean i want to run this in such a way that it should send me the alert everytime the condition is met. Please let me know how will script keep executing so that as many times the condition is met it will send me alert mail.

Regards,
Ankit
 
Old 11-05-2012, 11:49 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Are you sure about that? You may need to reconsider your requirements.

You are saying that when a value exceeds some defined threshold, a mail message should be sent. Following that event, the value continues to exceed the threshold, so a mail must again be sent. How quickly do the second and all subsequent e-mails need to be sent? Or should the algorithm be different?

You can check the alarm status on a periodic basis (1-minute granularity) using cron to launch your process monitor. It doesn't seem to make sense to send an e-mail every time the alarm condition is true.

--- rod.
 
Old 11-05-2012, 12:08 PM   #3
ankitpandey
Member
 
Registered: Jan 2012
Location: Mumbai
Posts: 63

Original Poster
Rep: Reputation: Disabled
Thanks for the response.

After first alert mail is sent, the second one should follow after 10 mins. I don't have permission to use cron job, can i do this without using cron job ?

Regards,
Ankit
 
Old 11-05-2012, 01:22 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
You should be able to create a script that sleeps for 10 minutes (600 seconds), and then performs the test, sending an e-mail as necessary.
Code:
#! /bin/bash

while [ 1 ]; do

   echo "Checking alarm value..."
   #
   #  Run your test here, setting global variables, 
   #  or whatever works for your test

   if [ alarmValue -gt alarmLimit ]; then
      #
      #   Send e-mail
      echo "Sending e-mail to ankitpandey"
   fi

   #
   #   Wait ten minutes for next test
   sleep 600

done
--- rod.
 
1 members found this post helpful.
Old 11-05-2012, 01:32 PM   #5
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,771
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
Quote:
Originally Posted by ankitpandey View Post
Thanks for the response.

After first alert mail is sent, the second one should follow after 10 mins. I don't have permission to use cron job, can i do this without using cron job ?

Regards,
Ankit

Your script can use a pattern similar to the following:

do {
if( alarm_exists() ) {
complain( "date", "time", "message" );
sleep( NAP_TIME );
until ( stopRunning == TRUE );

This can run at the user level so long as 'alarm_exists()' can learn what is needed
from your process in question. The longer the value of NAP_TIME, the smaller the
system load your script presents and the coarser the granularity of your complaints.
Any of the popular scripting languages will implement similar code.

The above approach does polling for the error condition. Depending on your process,
you might be able to enable and configure an "application event" such that your
script waits for that event and responds when it happens. I think this involves 'dbus'
but I don't know. Such an event catcher might need to field multiple events and complain every Nth occurrence. NOTE -- I've seen this done, but don't know the current implementations.

Let us know what you sort out,
~~~ 0;-Dan
 
Old 11-05-2012, 01:40 PM   #6
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,771
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
Quote:
Originally Posted by ankitpandey View Post
Thanks for the response.

After first alert mail is sent, the second one should follow after 10 mins. ...
Are you wanting the email to nag you until you respond somehow?
In that case, your process creates the error condition.
Your watchdog script notices and makes its complaint announcement.
After a complaint, the watchdog then looks for some acknowledgement.
After SOME_TIME, the watchdog repeats its complaint until it
gets the desired acknowledgement.

Logically, ERROR_EXISTS is a separate state from COMPLAINT_SENT which is
separate from COMPLAINT_ACKNOWLEDGED.

Think about your automobile.
Most ding or buzz with the keys in the dash and the door open.
You want the door open and you know where the keys are but that
blankety-blank-bleeping dinger just keeps making noise. Wouldn't you
like some way to say, "Thanks, I know where the keys are." to stop
the nagger? Would it be better if once acknowledged, you'd get a
fresh complaint after SOME_TIME if the keys remain in the dash?

Good luck. Keep us posted,
~~~ 0;-Dan

Last edited by SaintDanBert; 11-05-2012 at 01:42 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Handling OOM Problem and Alerting devUnix Linux - Server 5 08-11-2011 01:59 AM
CentOS 4.6:Yum information and alerting harry edwards Linux - Server 3 01-27-2008 09:03 PM
System Performance Alerting zeeple Linux - Server 2 08-08-2007 10:59 AM
LVS + monitoring and alerting VincentB Linux - Networking 0 11-16-2006 01:12 PM
Snort alerting with Swatch? ladyath Linux - Security 1 09-08-2004 04:22 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration