Saturday 6 February 2016

Zabbix and authenticated smtp email using gmail's servers


I'm using Zabbix to monitor my personal VMware server and VMs running on it. It's running as a VM on the same ESXi host. Not ideal but it works.

For alerting I wanted to use email but don't have my own mail sever, however I do have gmail account.

Gmail uses authenticated SMTP, however Zabbix doesn't support this. I did find though that Zabbix can use scripts for alerting and looking online, I found the answer on Github where someone had already solved this problem.

I've tested the script in this repository and it worked with only needing to set the username (email address) and password.

N.B. If you are using 2 factor authentication with Google, then you will need to generate an App password for the script to run.

https://gist.github.com/superdaigo/3754055

The below is based on Ubuntu 14.04 LTS:

You can find the location that alert scripts are stored in from the /etc/zabbix/zabbix_server.conf file.
This is normally: /usr/lib/zabbix/alertscripts

        admin@zabbix:/etc/zabbix$ sudo grep alert zabbix_server.conf
     # How often Zabbix will try to send unsent alerts (in seconds).
     # Full path to location of custom alert scripts.
     # AlertScriptsPath=${datadir}/zabbix/alertscripts
     AlertScriptsPath=/usr/lib/zabbix/alertscripts

The script from https://gist.github.com/superdaigo/3754055 should be saved to:  /usr/lib/zabbix/alertscripts with the extension ".py", e.g. "gmail-suth-smtp.py".

It then needs to be made executable and give zabbix permission to run it, most easily done with:

     sudo chmod +x gmail-suth-smtp.py

     sudo chown root:zabbix gmail-suth-smtp.py

You can now test is by running it - if you don't give it the right parameters it will let you know what they are.

      admin@zabbix:/usr/lib/zabbix/alertscripts$ python ./gmail-auth-smtp.py
      requires 3 parameters (recipient, subject, body)
      $ zabbix-gmail.sh recipient subject body
/alertscripts$ python ./gmail-auth-smtp.py a.user@gmail.com TestSubject Zabbix

Configuring Zabbix to use the script

Create a new Media Type:

On your Zabbix server, go to the Administration Tab, Media Types, in the top right, click "Create Media Type". As you can see, as I am not using the default alert types, so I have disabled them.




Configure Zabbix to use the new media type:
Click on the Configuration tab, Actions section.

The default Action is disabled, "Report problems to Zabbix administrators" and is set to use all Media Types.

Click on this action and then its Operations tab, then on the Edit button for the Action Operations section.

Half way down (highlighted) is the "Send only to" this can be changed to a specific type, in this case the gmail-auth-smtp.

N.B. do not use the [Update] button at the very bottom just yet, you need to use the smaller "Update" button within the section first. Otherwise the section settings won't get saved.



Setting the email address for the user and the media type

To set an email address for the user for the media type this is done via Administration, Users.
Edit the User and click on the Media tab.
Click on Add or Edit if one exists.
Set the "Type to" be: gmail-auth-smtp
Then set the "Send to" to the desired email address.

N.B. It is possible to bulk Add and Modify User's media using the API and say a csv file of user and email address. I say this, as I haven't found a way in the GUI to do it in bulk, e.g. CSV import. The import/export xml does not lists users as option. https://www.zabbix.com/documentation/2.4/manual/xml_export_import

API Documentation for adding and modifying users media types. 


Wednesday 10 September 2014

PSCP and an oddity of it (force it to use scp)


PSCP is a useful Windows SCP command line client; which tonight caught me out when working with OpernWRT. It doesn't just stick to SCP but wants to do SFTP too.

I was surprised when I connected using PSCP that my OpenWRT stated that it had been asked for SFTP. My request below was for a recursive copy of the OpenVPN certificates.

C:\Program Files (x86)\PuTTY>pscp -r root@192.168.1.254:/etc/easy-rsa/keys c:\certs
root@192.168.1.254's password:
ash: /usr/libexec/sftp-server: not found
Fatal: Received unexpected end-of-file from server

Testing within the OopenWRT router from and to itself worked fine.

root@OpenWrt:~# scp -r root@192.168.2.254:/etc/easy-rsa/keys/ ./
root@192.168.2.254's password:
index.txt

Looking at the command line options of PSCP, pscp /? I came across the argument -scp which forces PSCP to use SCP and not SFTP.

Solution

So it should look like this: 

>pscp -r -scp root@192.168.1.254:/etc/easy-rsa/keys c:\certs

C:\Program Files (x86)\PuTTY>pscp /?
PuTTY Secure Copy client
Release 0.63
Usage: pscp [options] [user@]host:source target
       pscp [options] source [source...] [user@]host:target
       pscp [options] -ls [user@]host:filespec
Options:
  -V        print version information and exit
  -pgpfp    print PGP key fingerprints and exit
  -p        preserve file attributes
  -q        quiet, don't show statistics
  -r        copy directories recursively
  -v        show verbose messages
  -load sessname  Load settings from saved session
  -P port   connect to specified port
  -l user   connect with specified username
  -pw passw login with specified password
  -1 -2     force use of particular SSH protocol version
  -4 -6     force use of IPv4 or IPv6
  -C        enable compression
  -i key    private key file for authentication
  -noagent  disable use of Pageant
  -agent    enable use of Pageant
  -batch    disable all interactive prompts
  -unsafe   allow server-side wildcards (DANGEROUS)
  -sftp     force use of SFTP protocol

  -scp      force use of SCP protocol


Monday 28 October 2013

Vegan Lemon Drizzle



This is a really easy cake to make, it's vegan and very tasty.

This is based on the vegan chocolate orange cake that
I also make. Pictures to follow the next time I make one.


What you will need

19cm x 7cm tin.
I use a non-stick one with a pop-up base.See notes below about using a wider tin.

A cocktail stick or small skewer to make holes in the cooked cake to allow the drizzle to infuse.

Pre-heat the oven to 160 degrees Celsius.

Prep time: 10 minutes + washing up ;)
Cook for 50 minutes on the middle shelf - it will be moist in the middle.

Or

Cook for 55 minutes and it will be cooked through, and slightly moist.

Dry ingredients

325g White self raising flour
220g Caster sugar or Muscovado (slightly healthier)
15g Bicarbonate of soda
The zest of 1 lemon
50g of caster sugar for the drizzle

Liquid Ingredients

135 ml vegetable oil

The juice of 2 medium lemons. 1 for in the cake and the other for the drizzle.

The juice of 1 lemon, which is approx 50ml. N.B. The total amount of lemon juice combined with soya milk should be 350ml. If oyu use 47ml of lemon juice then use 303ml of Soya milk.

300 ml of unsweetened soya milk


Special notes

Don't be tempted to use sweetened soya milk. It's normally sweetened with apple juice and gives cakes a funny taste.

If you want a sweeter cake, use 250g of sugar. I've reduced it over time.

I use vegetable oil from Rapeseed as it is supposed to lower cholesterol.

If you want to you can line the tine with baking paper; I've never needed to with my tins.

You may want to experiment with a wider tin. With the 7cm deep tin, it gets slightly crispy on top. If you use a wider tin you may want to reduce the cooking time slightly, by 5 minutes.

Method

Sieve the dry ingredients together and mix thoroughly.

Measure and mix the liquid ingredients separate from the dry ones.

In stages, add the liquid to the dry ingredients and mix, be gentle though as it makes quite a runny mix.

Unlike a sponge cake where you should spoon the mixture to preserve the air, you can poor this in to the tin. Using a glass bowel a silicon spatula will allow you to get all of the mixture in the tin.

The drizzle

Just before the cake is ready to come out mix 50g of caster sugar and 50ml or the juice of one lemon together.

Once the cake is cooked, take it out of the oven and leave it in the tin.

With your cocktail stick or skewer make holes that go half way or more in the top of the cake all over the surface.

Using either a spoon or the bowl cover the cake with the drizzle. If the cake has a shallow in the middle you may want to put the tin on a wedge or set it at an angle so that all the juice doesn't seep only in to the middle.

Allow to cool and then remove from the tin.

Vegetable oil and soya milk with lemon juice.






Tuesday 24 September 2013

Super quick Vegan Butter Icing

This makes a really quick "butter" icing. I use soya fat so that it's vegan.
The quantities below will give you enough to do the middle and top of a cake, with possibly a little left over as a very naughty snack ;)

Ingredients

2 tablespoons of cocoa powder. Neither level or heaped, just a happy in the middle tablespoon.

175g icing sugar

1 tablespoon soya butter. Same as the cocoa, not too much or too little ;)

Minimum of 2 tablespoons of near boiling water

A small dash of orange oil or essence

Method

Throughly mix the cocoa and icing sugar so that there is no marbling in colour.

Make a well and place the soya fat in.

Poor in a very a small dash of orange oil.

Add the water for the first two tablespoons one at a time. You may need to add a little more water, if it's too dry, (teaspoons) and mix until smooth.

Or

You may need to add a little more icing sugar if it's to thin.

Monday 23 September 2013

Vegan Chocolate Orange Gateau


This is a really easy cake to make, it's vegan and very tasty.

What you will need

19cm x 7cm tin.
I use a non-stick one with a pop-up base.
See notes below about using a wider tin.


Pre-heat the oven to 160 degrees Celsius.

Prep time: 10 minutes + washing up ;)
Cook for 45 minutes on the middle shelf - it will be moist in the middle.

Or

Cook for 50 minutes and it will be cooked through, and slightly moist.

Dry ingredients

275g White self raising flour
220g Caster sugar or Muscovado (slightly healthier)
50g Cocoa powder - I use Green & Blacks as it's got a strong cocoa taste.
15g Baking Powder

Liquid Ingredients

135 ml vegetable oil
350 ml of unsweetened soya milk
1 tsp or orange oil / essence

Special notes

Don't be tempted to use sweetened soya milk. It's normally sweetened with apple juice and gives cakes a funny taste.

If you want a sweeter cake, use 250g of sugar. I've reduced it over time; if you ice it with a vegan butter icing it will still be sweet without the extra 30g.

I use vegetable oil from Rapeseed as it is supposed to lower cholesterol.

If you want to you can line the tine with baking paper; I've never needed to with my tins.

You may want to experiment with a wider tin. With the 7cm deep tin, it gets slightly crispy on top. If you use a wider tin you may want to reduce the cooking time slightly, by 5 minutes.

Method

Sieve the dry ingredients together and mix thoroughly.

Measure and mix the liquid ingredients separate from the dry ones.

In stages, add the liquid to the dry ingredients and mix, be gentle though as it makes quite a runny mix.

Unlike a sponge cake where you should spoon the mixture to preserve the air, you can poor this in to the tin. Using a glass bowel a silicon spatula will allow you to get all of the mixture in the tin.

Allow to cool so that you can ice it.  N.B. Really quick vegan butter icing recipe to follow.

Evenly mixed dry ingredients with no marbling (flour and cocoa not mixed). 


Vegetable oil and soya milk with orange essence.


It makes a runny cake mix.





Wednesday 31 October 2012

3Com 4250 Password Reset

I post this in case it may help someone in the situation I found myself in, not being able to log in to a 3Com 4250T switch. I found the answer on a website, however the answer was incomplete and required some post answer implementation work to get the switch password reset.

I would have liked to post my additional steps against the original post, however I was greated with the following response from the site: "This comment has been deleted by WP Hashcash" which was disapointing.

http://www.geeklab.info/2011/02/recover-the-password-of-a-3com-4250t-switch/

Once you have done the reset using the recover/recover, pull the plug, you will need to connect via null modem cable or telnet to set a new password. The web front end will not let you in with just the username admin.

The default IP of the switch will be 169.254.100.100 with subnet mask 255.255.0.0
I used PuTTY for a telnet session and was presented with the following:

*** Password Recovery Mode ***
Enter the new password for the admin user:
Re-enter the new password:
The Password Recovery feature is enabled.
Enter new value (enable,disable)[enable]:

I did not enter a password and just pressed enter 3 times for the default blank password and to leave the recovery mode still enabled.