Coder Social home page Coder Social logo

icinga2-api-examples's Issues

Do you plan to change this script for the newest version - 2.8.0?

if File.file?("pki/" + @@node_name + ".crt")

cert_file = File.read("pki/" + @@node_name + ".crt")

key_file = File.read("pki/" + @@node_name + ".key")

ca_file = File.read("pki/ca.crt")

it should be changed from pki to /var/lib/icinga2/certs

Does not work with Python 3.6

This script doesn't seem to work with python 3.6. Mainly, print statements now need parenthesis and it seems a 'list' function needed added when getting the host, service, and notifications. I seemed to be able to get it running with the following changes. Not a coding expert but thought I'd post what I had here for you to review...

#!/usr/bin/env python

# pip install icinga2api
# https://github.com/tobiasvdk/icinga2api
import os
import argparse

from icinga2api.client import Client

# use a helper to fetch our cut down object names
def getObjects(client, type_name):
    if 'Notification' == type_name:
        return client.objects.list(type_name, attrs=['__name'])
    else:
        return client.objects.list(type_name, attrs=['__name', 'groups'])

# use a helper to convert the full blown object dictionary into a list of __name elements
def getNameList(objects, group = ''):
    if group:
        return map(lambda x : x['attrs']['__name'], filter(lambda y : group in y['attrs']['groups'], objects))
    else:
        return map(lambda x : x['attrs']['__name'], objects)

def diffList(l1,l2):
    l2 = set(l2)
    return [x for x in l1 if x not in l2]

# add connection details
parser = argparse.ArgumentParser()
parser.add_argument("-H", "--hosturi", help="URL to icinga2 API", required=True)
parser.add_argument("-u", "--username", help="Username to connect to API", required=True)
parser.add_argument("-p", "--password", help="Password to connect to API", required=True)
parser.add_argument("-g", "--group", help="Group to filter", required=False)
args = parser.parse_args()

client = Client(args.hosturi, args.username, args.password)

hosts = getObjects(client, 'Host')
services = getObjects(client, 'Service')
notifications = getObjects(client, 'Notification')

#debug
#print (hosts)
#print (services)
#print (notifications)


if not args.group:
    h_names = list(getNameList(hosts, False))
    s_names = list(getNameList(services, False))
else:
    h_names = list(getNameList(hosts, args.group))
    s_names = list(getNameList(services, args.group))

n_names = list(getNameList(notifications))

found_h_names = []
found_s_names = []

for n in n_names:
    split_arr = n.split("!")
    if len(split_arr) == 2:
        for h in h_names:
            # debug
            # print (n + " " + h)
            if h in split_arr[0]:
                found_h_names.append(h)

    if len(split_arr) == 3:
        for s in s_names:
            # debug
            # print (n + " " + s)

            # rebuild the matched full service name with host!service
            split_s_full_name = split_arr[0] + "!" + split_arr[1]

            if s in split_s_full_name:
                found_s_names.append(s)


print("Hosts without notification")
print (", ".join(diffList(h_names, found_h_names)))
print ("")
print("Services without notification")
print (", ".join(diffList(s_names, found_s_names)))

Acknowledge a specific service checks

Hi ,

I would like to one specific service check from the API for a specific host. Do you know what is the API for the same.

Lets say , I have a service called "http" from hosts - nagios1.example.com. I would like to acknowledge only this service check.

Thanks
Aravind

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.