#!/usr/bin/env python

#
# This file was written by Hummdis Communications.
# Copyright (c) 2011, Hummdis Communications.
# http://www.hummdis.com
#
# Write to: questions@hummdis.com with questions.
#

# Set your port # here if not 55343
port = 55343

import socket
import sys
import string

def usage():
    print """Syntax Error
    
Nagios(r) Plugin to Check Quickbooks port status.
Copyright (c) 2011, Hummdis Communications. All rights reserved.

Usage:
    check_quickbooks <ip>

Example:

    check_quickbooks 10.1.0.15

    or

    check_quickbooks 10.1.0.15

Options:
    hostname - Hostname can be just the hostname of the system, at which point
        this process will append the local domain. It can be in IPv4 address
        or it can be a Fully Qualified Domain Name (FQDN).
"""
    return

if len(sys.argv) != 2:
    usage()
    sys.exit(2)
    pass

host = sys.argv[1]

# Check if the Quickbooks port is open.
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(10)
try:
    sock.connect((host, port))
except Exception,e:
    print "Error! Port %d closed - Quickbooks not running!" % port               
else: 
    print "Quickbooks OK - %d open" % port
    
sock.close()
    
sys.exit(0)
