Announcement

Collapse
No announcement yet.

Python script and exit code

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Python script and exit code

    Hello,

    I create un script you do a json to check webservice.

    i don't find the correct exit code for my check centreon :

    The script is :

    # -*- coding: utf-8 -*-
    #!/usr/bin/python


    import socket
    import sys
    import json,simplejson
    import ssl, pprint

    # Exit statuses recognized by Nagios
    UNKNOWN = -1
    OK = 0
    WARNING = 1
    CRITICAL = 2

    # Create a TCP/IP socket
    #sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    # Connect the socket to the port where the server is listening
    server_address = ('webserviceserver', porttoconnect)
    #print >>sys.stderr, 'connecting to %s port %s' % server_address
    RETOUR=1
    try:
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    ssl_sock = ssl.wrap_socket(sock,
    server_side=False,
    ca_certs="server.crt",
    cert_reqs=ssl.CERT_REQUIRED,
    ssl_version=ssl.PROTOCOL_TLSv1)
    ssl_sock.connect(server_address)
    # Send data
    # customerNumber;Latitude;N/S;Longitude;E/W;Altitude;NombreSattelites;HDOP;PRIORITE

    #### JSON
    message = {'Function':'AUTH','EMAIL':'usermail','PASSWORD':' user password'}
    message = json.dumps(message)
    #print >>sys.stderr, 'sending "%s"' % message
    ssl_sock.send(message)

    #JSON.stringify
    datarcv = ssl_sock.read()
    data = simplejson.loads(datarcv)
    if (data['LoginState'] == True ):
    print("OK")
    ssl_sock.close()
    sock.close()
    sys.exit(0)
    else:
    print("CRITICAL")
    ssl_sock.close()
    sock.close()
    sys.exit(2)

    finally:
    ssl_sock.close()
    sock.close()


    On the server this script return correctly OK ou CRITICAL

    I use this commandlin in centreon : "/usr/bin/python2.6 /usr/lib/centreon/plugins/check_webservices.py"

    But i have this answer : (No output returned from plugin)


    outch !!!!!!

    thks for you help !


Working...
X