Monitoring web apps using html forms for logging in

Several times I’ve wanted to monitor if login actually works on webapplications that uses html forms for user validation. Today I made a simple bash nagios plugin to do that. It uses curl and checks it’s output. Curl supports POST variables.
The plugin also checks the unixtime before and after the curl command is being run, then does and expr to find the diff and makes nagios performance data of it.

Feel free to copy paste the code and use it for your own purpose.

#!/bin/sh
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
#This is what we get after a successful login
MATCH="bladiblah successful login bladiblah"
#delete the tmp file before writing a new one
rm /tmp/login_check
#Grab the unixtime before the command runs
BEFORE=`date +%s`
#Login to the app
/usr/bin/curl -H "host: example.com" -F mail="mail@example.com" -F userPassword="fail" http://111.111.111.111 -o /tmp/login_check > /dev/null 2>&1
#Grab the unixtime after the command have been run
AFTER=`date +%s`
DIFF=`/usr/bin/expr $AFTER - $BEFORE`
#Check tmp file if it matches our successful login
CHECK=`grep "$MATCH" /tmp/login_check`
if [ "$CHECK" = "$MATCH" ]; then
#WIN!!
echo "OK. Login successful. | response=$DIFF"
exit 0
else
#FAIL!!
echo "CRITICAL. Login failed."
exit 2

And as always, sorry about the wordpress formating of the code.

Tags: , , , , , , ,

Easy peasy ssh key authentication

You are on your job workstation, and you are SICK and TIRED of typing your password everytime you ssh to one of your corporate l33t h4xx0r boxes. Lets see how we easy as hell can use ssh keys to authenticate:

As your normal user on your workstation:
ssh-keygen -t rsa
This command makes your unique id for other servers to recognize when you ssh to them.
If you want passphrase you make one, everything else goes by default.

Lets make your servers recognize you and your key:
ssh-copy-id -i ~/.ssh/id_rsa.pub user@superhaxxorserver.com

Now you can do this without having to type a password:
dingle@berry-desktop:~$ ssh horsepr0n.mine.nu apt-get moo
(__)
(oo)
/------\/
/ | ||
* /\---/\
~~ ~~
...."Have you mooed today?"...

Tags: , , ,