#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# check_tsm - Check Tivoli Agent from Nagios
#
# Version: 1.0
# Author : Jonas Bjork <jonas.bjork@gmail.com>
# Date   : 2016-08-15
# License: GNU General Public License, version 2 (GPL-2.0)
#
import urllib2
import sys


errors = { 'OK' : 0, 'WARNING' : 1, 'CRITICAL' : 2, 'UNKNOWN' : 3, 'DEPENDENT' : 4 }

response = urllib2.urlopen('http://127.0.0.1:1581/BACLIENT')
headers = response.info()
server = headers['Server']

if server == "TSM_HTTP/0.1":
    state = "OK"
    comment = "Got response from TSM Agent"
else:
    state = "CRITICAL"
    comment = "Did not get response from TSM Agent"


print "%s - %s" % ( state, comment)
sys.exit(errors[state])

