API acknowledge-problem - am I doing it right?

Perhaps I’m just being stupid, which isn’t unlikely, but just in case: I’m acknowledging certain host problems, and I can see in the web intf that they are ‘handled’, but I can’t find my comments anywhere. This is my (python) code:

    @fn acknowledge(self)
    @return True if the host object was acknowledged sucessfully, False otherwise
    def acknowledge(self,author,comment):
        except Exception,arg:
            print 'Acknowledge %s failed\n%s'%(self.objnm,arg)
            return False
        return 'error' not in r.json()

Surely I should be able to see why a host or service or object is acknowledged?


I might have overseen it, but do you set the correct header?

'Accept': 'application/json'

You might also want to have a look into the example python API client in the documentation: https://icinga.com/docs/icinga2/latest/doc/12-icinga2-api/#example-api-client-in-python


1 Like

Hi Michael,

Yes, I use that header - in fact, I copied my initial code from the example client you mention. I’ll have to dig deeper into my code and see what is going on - maybe this call is failing silently in some way.
In fact, it was failing - I created a small bit of python code, that uses the same classes and added some debug traces:

bash-4.2$ ./host ack cx1-108-6-4 debug
host.init node: cx1-108-6-4.cx1.hpc.ic.ac.uk
host.ack url https://zenoss.hpc.imperial.ac.uk:5665/v1/actions/acknowledge-problem?type=Host&host=cx1-108-6-4.cx1.hpc.ic.ac.uk
host.ack data {'comment': 'Manual acknowledgement', 'author': 'admin'}
host.ack result <Response [404]>
cx1-108-6-4.cx1.hpc.ic.ac.uk acknowledged
bash-4.2$ Connection to admin.cx1.hpc.ic.ac.uk closed.

So, I don’t find the host object (which I know exists); the code doesn’t detect the failure because I look for the string ‘error’ in the results, which isn’t there, but that is minor problem. What is the correct form of the URL in this case?

Has your Icinga 2 API user the correct permissions?

The url looks fine to me , I wrote a simple python snippet where I use your url format to acknowledges a host problem.


python test.py
/home/michael/.local/lib/python2.7/site-packages/urllib3/connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

It prints out the url and status code of the request. The warning appears because I just ignore the certificate, which is insecure and not recommended. Have a look in the example Python API client in the documentation for a proper certificate verification.

Are you sure the given host matches with the host object name? What is the output of:

curl -k -s -u icinga:icinga 'https://localhost:5665/v1/objects/hosts?host=myhostobject&pretty=1'

Where myhostobject is identical with the host from your example above?


1 Like

Ah! I see the problem now: the permissions were wrong. I’ve fixed that now. Thx for your help.

1 Like