npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

icinga2-api

v1.1.2

Published

Nodejs Modul to control Icinga2 through api

Downloads

12

Readme

icinga2

Icinga2 Remote api module. You can create, remove, update, etc of icinga2 objects

Icinga2 api doc

Installation

npm install icinga2-api

Getting started

Example

  1. Check if the host "4demo" exist in monitoring.
  2. If not, create host "4demo".

Updated

The parameters 'group' and 'onServer' was removed from methode 'createHost' and 'createService'

const icingaapi = require('icinga2-api');

var icingaServer = new icingaapi("icingas2server.local", "5665", "apiUser", "apiUserPass");
    icingaServer.getHostState("4demo", function (err, result) {
        if (err) {
            if (err.Statuscode == "404") {
                console.log("Host 4demo on monitoring was not found, create one");
                
                // Create a host on icinga2.
                icingaServer.createHost("passive-host", "4demo", "4Demo Server", function (err, result) {
                    if (err) {
                        console.error(err);
                    } else {
                        console.log("Host 4demo was created successfull");
                    }
                });
            }
            console.error(err);
        } else {
            console.log(result);
        }
    })

Methods

  • getServices = function (callback)
  • getService = function (ServerName, ServiceName, callback)
  • getHosts = function (callback)
  • getHost = function (ServerName, callback)
  • getHostFiltered = function (filter, callback)
  • getServiceFiltered = function(filter, callback)
    • filter =
        {
            "filter": "service.vars.Backup_Server == servicename",
            "filter_vars": {
                "servicename": "backupServer"
            }
        }
  • getServiceWithState = function (state, callback)
    • state = 0/1/2
  • createHost = function (template, host, displayname, callback)
    • template - icinga2 host-template
    • onServer = "dockerHost", set a custom variable in icinga2
  • createService = function (template, host, service, displayname, callback)
  • createServiceCustom = function (serviceObj, host, service, callback)
    • serviceObj =
      var serviceObj = JSON.stringify({
          "templates": ["passive-service"],
          "attrs": {
              "display_name": "Service Top",
              "vars.group": "adito",
              "vars.server": "dockerdmz"
          }
      })
  • createHostCustom = function (hostObj, host, callback)
    • hostObj
      var hostBody = JSON.stringify({
          "templates": ["passive-host"],
          "attrs": {
              "display_name": "4Demo Server",
              "vars.group": "adito",
              "vars.server": "dockerdmz"
          }
      })
  • createServiceCustom = function (serviceObj, host, service, callback)
    • serviceObj
      var serviceBody = JSON.stringify({
          "templates": ["passive-service"],
          "attrs": {
              "display_name": "Service on 4Demo Server",
          }
      })
  • deleteHost = function (host, callback)
  • deleteService = function (service, host, callback)
  • setHostDowntime = function (dObj, hostname, callback)
    • dObj (downtime object)
          var dObj = {
              'type': 'Host',
              'start_time': actTime,
              'end_time': endtime,
              'author': 'icingaadmin',
              'comment': "Downtime for Backup"
          }
  • setFilteredDowntime = function (dFilter, callback)
    • dFilter (example: set downtime for all server where custom variable server = dockerhost)
          var setDownTimeObject = {
              'type': 'Host',
              'start_time': actTime,
              'end_time': endtime,
              'author': 'icingaadmin',
              'comment': "Downtime for Backup",
              'filter': 'host.vars.server == server',
              'filter_vars': {
                  'server': "dockerhost"
              }
          }
  • removeFilteredDowntime = function (dFilter, callback)
    • dFilter(remove all Downtimes with autor "icingaadmin" and custom vars server "dockerhost"
          var removeDownTimeObject = ({
              "type": "Downtime",
              "filter": "downtime.author == filterAuthor && host.vars.server == filteredHost",
              "filter_vars": {
                  "filterAuthor": "icingaadmin",
                  "filteredHost": "dockerhost"
              }
          })
  • disableHostNotification = function (hostname, callback)
  • setHostState = function (host, hostState, StateMessage, callback)
  • setServiceState = function (service, host, serviceState, serviceMessage, callback)
  • getHostState = function (hostName, callback)
  • getServiceTemplates = function(callback)
  • checkExistServiceTemplate = function(name, callback)
  • getHostTemplates = function(callback)
  • checkExistHostTemplate = function(name, callback)
  • setServicePerfdata = function (service, server, state, output, perfarr, callback)
    • perfarr (Data array) - show process-check-result in icinga2 api doc
          var perfdataArr = ["Memory in %=" + memUsedinPerc + "%;" + aditoMemWarn + ";" + aditomemErr + ";0"]
  • setHostPerfdata = function (server, state, output, perfarr, callback)
  • updateHostAttr = function (hostObj, host, callback)
    • hostObj
      var hostObj = JSON.stringify({
          "templates": [icingaConf.templatehost],
          "attrs": {
              "display_name": "Adito Server Public",
              "vars.group": "adito",
              "vars.AditoServerName": "aditoServer",
              "vars.AditoServerVersion": "4.6.34",
              "vars.AditoStartupTime": "Mo.",
              "vars.CPUs": "4"
          })
  • updateServiceAttr = function (serviceObj, host, service, callback)

Examples

Check test.js for more details