Jul 022015

I’ve just started working with Powershell recently and wanted to create a CSV file from scratch.
I thought it’d be as simple as piping a string to Export-CSV, however Export-CSV only takes objects.
This meant that I had to create my own objects to then dump into Export-CSV.
This wasn’t immediately obvious to me initially, as I’ve little experience with Powershell, but since I’ve worked out how to do it, I’m going to document it here for reference.

$csvContents = @() # Create the empty array that will eventually be the CSV file

$row = New-Object System.Object # Create an object to append to the array
$row | Add-Member -MemberType NoteProperty -Name "User" -Value "John Doe" # create a property called User. This will be the User column
$row | Add-Member -MemberType NoteProperty -Name "UserID" -Value "JD01" # create a property called UserID. This will be the UserID column
$row | Add-Member -MemberType NoteProperty -Name "PC" -Value "PC01" # create a property called PC. This will be the PC column

$csvContents += $row # append the new data to the array

$csvContents | Export-CSV -Path C:\tmp\user.csv

The code above will result in the following output

#TYPE System.Object
"John Doe","JD01","PC01"

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.

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+"""


smtpObj = smtplib.SMTP("smtpserver.example.com")
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

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 »

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 »

Jun 112015

In my last post, I looked at the $5 NAS from MSY and poked around the interface to see what it can do out of the box.

Now lets see what I can make it do!
Continue reading »