DX Unified Infrastructure Management

 View Only
Expand all | Collapse all

When Using Python and httlib to send UIM Rest API a request to create an alarm I always seem to get an error response and not sure why?

  • 1.  When Using Python and httlib to send UIM Rest API a request to create an alarm I always seem to get an error response and not sure why?

    Posted May 02, 2019 08:17 AM

    My issue is the integration we are using this with I usually use requests not httplib however due to the product we are trying to integrate I have to use httplib and python 2.7.x (not 3.x.x). I am able to make the connection with the basic auth it looks like however I am always getting an http 500 response and I am not sure why, any ideas?

     

    Script Below:

     

    import httplib, urllib

    import base64

    import string

    import json

     

    host = "REST API HOSTNAME"

    url = "/rest/alarms/createAlarm"

    username = 'UIM USERNAME'

    password = 'UIM PASSWORD'

    params = ({'source': 'HOSTNAME', 'ss_id': '1.1', 'supp_key': 'supression_key_alarm', 'level':'warning'})

     

     

    # base64 encode the username and password

    auth = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')

     

    webservice = httplib.HTTP(host)

    # write your headers

    webservice.putrequest("POST", url)

    webservice.putheader("Host", host)

    webservice.putheader("Content-Type", "application/JSON")

    #webservice.putheader("Accept", "application/JSON")

    webservice.putheader("Content-length", "%d" % len(json.dumps(params)))

    # write the Authorization header like: 'Basic base64encode(username + ':' + password)

    webservice.putheader("Authorization", "Basic %s" % auth)

     

    webservice.endheaders()

    webservice.send(json.dumps(params))

    # get the response

    statuscode, statusmessage, header = webservice.getreply()

    print "Response: ", statuscode, statusmessage

    print "Headers: ", header

    res = webservice.getfile().read()

    print 'Content: ', res

     

     

    This is always returning an http 500 error, and I am not sure why. I know the auth is working because if I remove it I get a 4xx error unauthorized. Very strange, anyone have any ideas/suggestions on why it might not be working?



  • 2.  Re: When Using Python and httlib to send UIM Rest API a request to create an alarm I always seem to get an error response and not sure why?
    Best Answer

    Broadcom Employee
    Posted May 02, 2019 08:30 AM

    hi

    in your sample your key value pair names are incorrect. I am not sure if you were doing shorthand or if those were the actuall names you are using.

    Please review the example Jason in the docs for the correct name pairs and use them exactly and see if that does not correct

     

    Alarm Calls - CA Unified Infrastructure Management Probes - CA Technologies Documentation 

     

    POST /rest/alarms/createAlarm HTTP/1.1 Accept: application/JSON Content-Type: application/JSON {     "level":"1",     "message":"Testmessage",     "metId":"MD8110AB685AA9D19C8F7F807FDAC306F",     "severity":"Informational",     "source":"w2k8r2-x64-lc",     "subsystemId":"1",     "suppressionKey":"",     "ciType":"1.1.2",         "ciName":"Disk Usage",     "custom1":"A custom property 1",     "custom2":"A custom property 2",     "custom3":"A custom property 3",     "custom4":"A custom property 4",     "custom5":"A custom property 5" }

     

    Also you are missing the servierty field which is required:

    Important! The severity and message fields are required when creating an alarm. The message field sets the alarm message. The severity field indicates the impact or importance of an alarm. The following numeric values are supported:



  • 3.  Re: When Using Python and httlib to send UIM Rest API a request to create an alarm I always seem to get an error response and not sure why?

    Posted May 03, 2019 05:20 AM

    Hi Howard,

     

    I knew it had to be something small I over looked, I was starring at this and it was driving me up a wall LOL. Thank you - you were correct and so was the documentation, I apparently overlooked or confused severity and level. As soon as I added severity everything worked. Thanks for the help!