Jun 222015
 

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

My Media type configuration

My Media type configuration

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

Share
Jun 182015
 

I recently had to verify a whole bunch of servers were responding to SNMP and had the correct DNS reverse look ups in Active Directory.
I used this little script so that it would ask me for an IP address and then do a ping, and then if a server was reachable over ICMP, a nslookup if a server responded to the SNMP Query for the system name.
Continue reading »

Share
Jun 152015
 

I recently found out that Telstra has a SMS API, and for now, it’s free to use for up to 1000 SMSes a month for Australians (sorry rest of the world).

As I’ve been building up Zabbix for our work environment where SMSes are used regularly to alert techs to critical alerts, this piqued my interest as this means that for now, I could have SMS alerts for my homelab, and potentially implement the same solution at work.
Continue reading »

Share
May 212015
 

One of the reason why I bought the IP camera in the first place was to replace a USB webcam that I was using to do some motion detection. The camera was plugged into a virtual machine and wasn’t very reliable so when I saw the IP Camera, it crossed my mind that it would be a nice cheap replacement for the webcam.

The first thing I needed to to do was configure the username and password on the IP Camera itself. This is to ensure that no one can log in to the webcam from the cloud service.

Configuring the IP Camera

I will be doing any setup for the IP Camera on the web interface as it’s a platform agnostic way of setting it up.
Log in to the camera by directing your browser to http://:99/ and entering your password.
The default credentials are “Admin” with a blank password.

Click on sign in on one of the modes, I’ve used the Chrome mode.
Menu

Click on the settings button in the bottom right hand corner, and then click on Users Settings in the right hand menu.
settings button
If you want to, you can change the name of the admin user here, I’ve set a password for my admin user here.
Click on Submit. The IP Camera will now reboot for the settings to take effect.

Configuring Motion

I’ll be using Motion for more than one device so I will configure it using separate configuration files for the camera in preparation for other cameras to also be added in. It’s possible to use a single configuration file if you want, but if there is a possibility of adding more cameras later on, it would be easier to start with multiple configuration files off the bat.

Configuring the Motion Daemon

There’s a few settings that I’ll be changing from the default Motion configuration.
First thing you should change is the line in /etc/default/motion. Change it to read from no to yes.

Next, we’ll have a look at motion.conf.
The following lines in there that I will be commenting out so that Motion doesn’t look for a local device. It’s possible that you don’t need to comment these line;s out, but I prefer to be thorough to ensure nothing unexpected happens.
videodevice /dev/video0
v4l2_palette 17
input -1
norm 0

There’s also a few lines you’ll need to update.
There are a couple of lines that set the resolution. By default, they are at 320 and 240.

width 320
height 240

Update these 2 lines to 640 and 480 like so

width 640
height 480

I’m also going to up the framerate from framerate 2 to framerate 30 to get some smoother video, Keep in mind that this is just a maximum framerate.

We’ll update the server options next so that you can access the control panel from another computer on the network.
There is a couple of lines like this –

stream_localhost on
webcontrol_localhost on

These needs to be changed to off like so –
stream_localhost off
webcontrol_localhost off

At the bottom of the configuration file, you will see some thread lines. We’ll need to uncomment one so we can put the settings for our first camera into one of the files.
From

; thread /etc/motion/thread1.conf

To

thread /etc/motion/thread1.conf

thread1.conf

If you’re only intending to use one camera then you don’t need to create this file, you’ll just need to do the following in the main motion.conf file.

In this file, we’ll need to set the URL for the camera itself.
Put this into a new file named /etc/motion/thread1.conf

netcam_url http://192.168.2.16:99/videostream.cgi?user="YOUR ADMIN USER HERE"&pwd="YOUR ADMIN PASSWORD HERE"

Replace the username and password with your own.
Save the file, and then you should be able to start motion with /etc/init.d/motion start
Then, using a player like VLC and browsing to the address of the computer running motion on port 8081 should get you a stream of the IP Camera.

Share
Apr 162015
 

I’ve been setting up SNMP Traps on Zabbix 2.4 to replace our current in place monitoring solution.
One of the hurdles that I’ve come across is trying to get all the traps setup.

An easy way of doing this is getting the MIB files for the traps that you’re getting, and converting them into configuration files for SNMPTT to use to parse the traps.
The snmpttconvertmib command will take a MIB file as an input, and spit out a configuration file suitable for SNMPTT.
Using an Oracle MIB file as an example –

snmpttconvertmib --in=ORACLE-ENTERPRISE-MANAGER-4-MIB.mib --out=/etc/snmp/snmptt.conf.ora-em4

This will produce a file for SNMPTT but Zabbix will not parse the traps yet as the FORMAT line isn’t quite what we need yet.
Next, we’ll use sed to do a global search and replace to make sure the FORMAT lines conform to the format that Zabbix requires.

sed -i 's/FORMAT/FORMAT ZBXTRAP $aA/g' /etc/snmp/snmptt.conf.ora-em4

The configuration file then needs to be added to the list of files that SNMPTT uses to parse the traps.
Open /etc/snmp/snmptt.ini file – assuming it’s in the default location – and scroll right down to the bottom of the file.
You will see the following lines –

snmptt_conf_files = <<END
/etc/snmp/snmptt.conf

Add the file you’ve just created to the end like so –

snmptt_conf_files = <<END
/etc/snmp/snmptt.conf
/etc/snmp/snmptt.conf.ora-em4

And you should start getting SNMP traps appearing in Zabbix – assuming you’ve already set up the item.

Share