External API call from icinga via python and Oracle VM Monitoring automation

This forum was archived to /woltlab and is now in read-only mode.
  • Hi,
    I am connecting to an external API and pulling the data to local. I have my python script ready and fetching the desired results.
    Let me brief a little before i get to the problem summary.

    ##My Python Script
    import sys
    import urllib
    import requests
    import json
    from time import sleep

    s.verify=False #disables SSL certificate verification

    s.headers.update({'Accept': 'application/json', 'Content-Type': 'application/json'})

    print ("baseUri: " + baseUri)

    for i in r.json():
    print ('{name} is {state}'.format(name=i['name'],state=i['serverRunState']))

    What this script does:
    1. authenticates with the OracleVM Manager API
    2. gets the list of host servers added & managed in this OVM Manager and the run status of the servers.

    Server1.abc.dd.xyz is DOWN
    Server2.abc.dd.xyz is RUNNING
    Server3.abc.dd.xyz is STARTING

    This is basically pulling the data from an external API. Now coming to the problem.
    1. How can i get this assigned to my icinga2 and
    2. get the out put of my script displayed as is in my icinga2 status.
    Because i have multiple other scripts which might fetch me different values, for example list of all vm machines running in a vm server with its VM name, operating system, uptime. These are data fetched from Oracle Delivered API collecting through python.

    Thanks in advance!

  • You need to find a way to evaluate such output, and also add thresholds to it. Printing the result set in one line (or more) following the plugin api specification is tremendously easy.


  • Thank you dnsmichi..
    let me give it with a example of what i am looking for..

    In Nagios you can define and run as below:

    define command { command_name check_hello_world command_line $USER1$/check_hello_world.py -m 'some message'}

    Check a host or service using the command:

    define service { use generic-service host_name some-host service_description Check using the hello world plugin (always returns OK) check_command check_hello_world}

    like wise how can define and easily call my python script in icinga2. Once i get this I will further explore on the thresholds and other variables to handle things.

  • Further checking some of your old posts. I went further adding command in icinga style.

    in Icinga2:

    object CheckCommand "getit" {
    import "plugin-check-command"
    command = [ "/usr/local/bin/python3.5 " + "/tmp/santi/sample.py"]

    apply Service "Plz Work" {
    import "generic-service"
    check_command = "getit"

    assign where host.name == NodeName

    Good News: No errors while compiling or restarting. And the new service got added. BUT!!
    Bad News: Getting the below error

    Plugin Output
    execvpe(/usr/local/bin/python3.5 /tmp/santi/sample.py) failed: No such file or directory

    I expect this should be running the command in the below format in my master server
    /usr/local/bin/python3.5 /tmp/santi/sample.py

    While i run the above line as is in my master server manually I am getting the desired output.

    # /usr/local/bin/python3.5 /tmp/santi/sample.py
    BLRDIBL214.abc.xyz is RUNNING
    blrdibl415.abc.xyz is RUNNING


  • Once your plugin is finished, you'll need a CheckCommand definition. That is described in the documentation chapter as well. But first things first - test your plugin to return proper output, performance data and exit status. Then you can dive into the integration into Icinga 2 - CheckCommand, Host, Service objects.

  • Hi dnsmichi,
    As suggested I got around a different method to get all my oracle vm hosts monitored in icinga. I went for the API call to both OVM and Icinga2 and get the hosts created and monitored basis my requirements.
    attaching my code.

    Key notes on the attached code:
    1. This identifies all the master servers and VM hosts from Oracle VM manager
    2. Checks if the Hosts in Oracle VM already exists in Icinga. If yes it will just enable notification for that host in icinga. If it does not exist it will get the operating system and host name from Oracle VM Manager and will add the host to icinga
    3. Based on the status of the VM host in Oracle VM Manager (running or stopped) it will enable and disable the notification in icinga for that host.
    While creating the host in icinga if the oracle vm host is already stopped it disabled the notification since i might have multiple VM hosts that are in stopped status. it will be monitored when the status of the VM Host is running automatically.

    Further to I am working on monitoring 2 things to add on top of this
    1. Monitoring all physical storage mounted for VM master server
    2. Deleting orphan hosts in icinga that does not exist in my Oracle VM. (Case scenario - The VM host might have been there in my OVM Manager and it got created in Icinga for monitoring, but later if the VM is deleted icinga might not know that it does not even exist. In this case the orphan host in icinga will not be listed in my current code. I am trying to identify such host entries comparing the list of hosts in icinga with the list of hosts in my OVM and fire a mail that host missing and then delete the host entry in icinga to limit the pain of notifications and manual interventions)

    The attached code is working perfectly fine and it creates and modifies the hosts in icinga as desired. I will share the final code with storage monitoring and deletion of orphan hosts once i complete and implement in my environment.

    Thanks a lot for your support and guidance across. You have been of great help and support for all my queries. And i am very much impressed the way it is simple to use icinga for monitoring.. Will keep exploring icinga and posting my queries..