Solved

Need To Add Email Alerts feature in CaiCai?

Posted on 2008-06-24
5
256 Views
Last Modified: 2010-04-16
Hi,

I am using CaiCai as Network Monitoring System (caicai.sourceforge.net). CaiCai uses ICMP to get status from devices. Nice application as it is not dependent on SNMP. It is web based and written in Python. I am alien to python.Whenever a device does not respond to pings from CaiCai then it generates error and posts them on a web page. This application does not have any email alerting mechanism. I want to add the email alerts mechanism to this application. Can some body help me out. I am attaching the error generating mechanism in caicai.
# updates data (or adds entry, is not present there) for errors_stats[]

# error_report is a matrix cell (which is a matrix itself) from the processed logfile

def update_errors_stats (error_report):

	error_duration = error_report[1] - error_report[0]

	

	line_counter = 0

	for i in errors_stats:

		if i[0] == error_report[2]:

			if errors_stats[line_counter][1] > error_duration:

				errors_stats[line_counter][1] = error_duration

			if errors_stats[line_counter][2] < error_duration:

				errors_stats[line_counter][2] = error_duration

			errors_stats[line_counter][3] += 1

			errors_stats[line_counter][4] += error_duration

			return ()

		line_counter += 1

	

	# entry not found, let's add one then

	entry_for_errors_stats = []

	entry_for_errors_stats.append (error_report[2])

	entry_for_errors_stats.append (error_duration)

	entry_for_errors_stats.append (error_duration)

	entry_for_errors_stats.append (1)

	entry_for_errors_stats.append (error_duration)	

	errors_stats.append (entry_for_errors_stats)

	return ()

Open in new window

0
Comment
Question by:Kamran Arshad
  • 3
5 Comments
 
LVL 17

Accepted Solution

by:
ramrom earned 500 total points
ID: 21865562
Take a look at the smtplib module. It is part of the Python distribution. There is sample code in the docs that will probably do the trick, which I show here.

You will have to make some changes (how msg is constructed, and where the SMTP server is).
import smtplib
 

def prompt(prompt):

    return raw_input(prompt).strip()
 

fromaddr = prompt("From: ")

toaddrs  = prompt("To: ").split()

print "Enter message, end with ^D (Unix) or ^Z (Windows):"
 

# Add the From: and To: headers at the start!

msg = ("From: %s\r\nTo: %s\r\n\r\n"

       % (fromaddr, ", ".join(toaddrs)))

while 1:

    try:

        line = raw_input()

    except EOFError:

        break

    if not line:

        break

    msg = msg + line
 

print "Message length is " + repr(len(msg))
 

server = smtplib.SMTP('localhost')

server.set_debuglevel(1)

server.sendmail(fromaddr, toaddrs, msg)

server.quit()

Open in new window

0
 
LVL 32

Author Comment

by:Kamran Arshad
ID: 21872927
Thanks a lot. I will experiment on this smtplib and hopefully get something out of it.
0
 
LVL 32

Author Comment

by:Kamran Arshad
ID: 21873714
Thanks for the thought. Ok lets keep it open and I will update you. So far I have done simple emailing using the python code you gave me. It is not Integrated with caicai and I am working on it. Will update you when any error or problem occurs.
0
 
LVL 32

Author Comment

by:Kamran Arshad
ID: 21914162
I am able to send emails from CaiCai NMS.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Python Assistance 7 73
regex to extract ip:john 17 69
DHCP Failover Relationship caveats 6 96
Resource cost of NAT vs routing 3 65
How to set-up an On Demand, IPSec, Site to SIte, VPN from a Draytek Vigor Router to a Cyberoam UTM Appliance. A concise guide to the settings required on both devices
As companies replace their old PBX phone systems with Unified IP Communications, many are finding out that legacy applications such as fax do not work well with VoIP. Fortunately, Cloud Faxing provides a cost-effective alternative that works over an…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now