I recently got my hands on a Linksys SRW2048 switch to use as the core of my home network. The main reason why I wanted this was for VLANs so I could start experimenting with them in my homelab, but as a bonus, the switch supports SNMP which means that I can use my Zabbix instance to monitor the stats on the switch.
If you’re a regular reader of my blog, you’ll know that I’ve set up a Motion daemon to monitor one of my IP Cameras.
Recently, I decided to also make a graph of the motion so that I easily track when motion was detected from my IP Camera. This was easily done with the Zabbix agent as I could send data straight into a Zabbix item with zabbix_sender
.
In my last post, I built a script to poll my modem via Telnet to retrieve ADSL stats.
In this post, I’ll be using the output of the last script to put the values into Zabbix so I have some history to refer to.
Continue reading »
I recently had a thought…I wonder if Zabbix can graph the fuel prices near me.
This thought was triggered by a news article I read about how the petrol station cycles have changed so that the cheapest fuel is on a Monday rather than a Wednesday like it used to be.
Continue reading »
I had to build my own email sender script for Zabbix as I needed some mangling done on the subjects that was being sent out.
I used python to build it so that I could then use some regex to strip out the garbage that I needed stripped out.
First thing you need to do is to create the email script for Zabbix to run when it receives an alert.
The default location for these scripts is /usr/lib/zabbix/alertscripts/
but this can be customised from the Zabbix server configuration file.
This is the python script that I used, I named it emailalert.py
, so the full path for this script should be /usr/lib/zabbix/alertscripts/emailalert.py
.
In this example script, I’m only removing text <EMAIL>
from any subjects that may have it. This is because some alerts that are being generated have an <EMAIL>
tag to enable Zabbix to recognise that the alert needs to go through email, however the team receiving the alert doesn’t want the <EMAIL>
tag on the subject line of the email they receive.
#!/usr/bin/python
import smtplib
import sys
import re
email = sys.argv[1]
subject = sys.argv[2]
body = sys.argv[3]
subject = re.sub('<EMAIL>',"",subject)
sender = "Zabbix <zabbix@example.com>"
message = """From: Zabbix <zabbix@example.com>
To: """+email+"""
Subject: """+subject+"""
"""+body+"""
"""
try:
smtpObj = smtplib.SMTP("smtpserver.example.com")
smtpObj.sendmail(sender,email,message)
print "Success"
except SMTPException:
print "Unable to send email"
Once the script has been created, you’ll need to add the script to the Media Types
under Administration
in Zabbix.
Create a new media type, and give it a name. I’ve called mine Email Script
.
For the type, choose Script
, and then for the Script Name, use the name that you’ve given the script. In my case, I’ve called it emailalert.py
Once this is done, you’ll need to set up email addresses for users that need emails through this new script by going to each user, and setting up a new media entry with the type being Email Script