Git Product home page Git Product logo

nagios-api's Introduction

Nagios API

nagios-api - presents a REST-like JSON interface to Nagios.

Description

This program provides a simple REST-like interface to Nagios. Run this on your Nagios host and then sit back and enjoy a much easier, more straightforward way to accomplish things with Nagios. You can use the bundled nagios-cli, but you may find it easier to write your own system for interfacing with the API.

Synopsis

nagios-api [OPTIONS]

Dependencies

Dependencies include:

  • diesel
  • greenlet
  • python-openssl

These should be available via pip/easy_install.

Usage

Usage is pretty easy:

nagios-api -p 8080 -c /var/lib/nagios3/rw/nagios.cmd\
-s /var/cache/nagios3/status.dat -l /var/log/nagios3/nagios.log

You must at least provide the status file options. If you don't provide the other options, then we will disable that functionality and error to clients who request it.

Using the API

The server speaks JSON. You can either GET data from it or POST data to it and take an action. It's pretty straightforward, here's an idea of what you can do from the command line:

curl http://localhost:8080/state

That calls the state method and returns the JSON result.

curl -d '{"host": "web01", "duration": 600}' -H 'Content-Type: application/json' http://localhost:8080/schedule_downtime

This POSTs the given JSON object to the schedule_downtime method. You will note that all objects returned follow a predictable format:

{"content": <object>, "result": <bool>}

The result field is always true or false, allowing you to determine at a glance if the command succeeded. The content field may be any valid JavaScript object: an int, string, null, bool, hash, list, etc etc. What is returned depends on the method being called.

Using nagios-cli

Once your API server is up and running you can access it through the included nagios-cli script. The script now has some decent built-in help so you should be able to get all you need:

nagios-cli -h

The original raw JSON mode is still supported by passing the --raw option.

Options

Below are the options taken on the CLI.

-p, --port=PORT

Listen on port 'PORT' for HTTP requests.

-b, --bind=ADDR

Bind to ADDR for HTTP requests (defaults to all interfaces).

-c, --command-file=FILE

Use 'FILE' to write commands to Nagios. This is where external commands are sent. If your Nagios installation does not allow external commands, do not set this option.

-d, --config-directory=PATH

The directory in which Nagios will look for object files and import hosts into its internal database for monitoring.

-s, --status-file=FILE

Set 'FILE' to the status file where Nagios stores its status information. This is where we learn about the state of the world and is the only required parameter.

-l, --log-file=FILE

Point 'FILE' to the location of Nagios's log file if you want to allow people to subscribe to it.

-o, --allow-origin=ORIGIN

Modern web browsers implement the Cross-Origin Resource Sharing specification from W3C. This spec allows you to host your JavaScript/HTML on one host and have it access an endpoint on a different service. This requires setting a header on the endpoint, which this option allows you to do.

You can simply set this header to ``` and not worry about it if you want to allow all access. For more information see the CORS specification.

-q, --quiet

If present, we will only print warning/critical messages. Useful if you are running this in the background.

API

This program currently supports only a subset of the Nagios API. More is being added as it is needed. If you need something that isn't here, please consider submitting a patch!

This section is organized into methods and sorted alphabetically. Each method is specified as a URL and may include an integer component on the path. Most data is passed as JSON objects in the body of a POST.

acknowledge_problem

This method allows you to acknowledge a given problem on a host or service.

{
  "host": "string",
  "service": "string",
  "comment": "string",
  "sticky": true,
  "notify": true,
  "persistent: true,
  "expire": 0,
  "author": "string"
}

Fields

host = STRING [required]

Which host to act on.

service = STRING [optional]

If specified, act on this service.

comment = STRING [required]

This is required and should contain some sort of message that explains why this alert is being acknowledged.

sticky = BOOL [optional]

default TRUE. When true, this acknowledgement stays until the host enters an OK state. If false, the acknowledgement clears on ANY state change.

notify = BOOL [optional]

default TRUE. Whether or not to send a notification that this problem has been acknowledged.

persistent = BOOL [optional]

default FALSE. If this is enabled, the comment given will stay on the host or service. By default, when an acknowledgement expires, the comment associated with it is deleted.

expire = INTEGER [optional]

default 0. If set, it will (given icinga >= 1.6) expire the acknowledgement at the given timestamp. Seconds since the UNIX epoch. Defaults to 0 (off).

author = STRING [optional]

The name of the author. This is useful in UIs if you want to disambiguate who is doing what.

add_comment

For a given host and/or service, add a comment. This is free-form text that can include whatever you want and is visible in the Nagios UI and API output.

{
  "host": "string",
  "service": "string",
  "comment": "string",
  "persistent: true,
  "author": "string"
}

Fields

host = STRING [required]

Which host to act on.

service = STRING [optional]

If specified, act on this service.

comment = STRING [required]

This is required and should contain the text of the comment you want to add to this host or service.

persistent = BOOL [optional]

Optional, default FALSE. If this is enabled, the comment given will stay on the host or service until deleted manually. By default, they only stay until Nagios is restarted.

author = STRING [optional]

The name of the author. This is useful in UIs if you want to disambiguate who is doing what.

cancel_downtime

Very simply, this immediately lifts a downtime that is currently in effect on a host or service. If you know the downtime_id, you can specify that as a URL argument like this:

curl -d "{}" http://localhost:8080/cancel_downtime/15

That would cancel the downtime with downtime_id of 15. Most of the time you will probably not have this information and so we allow you to cancel by host/service as well.

{
  "host": "string",
  "service": "string",
  "services_too": true
}

Fields

host = STRING [required]

Which host to cancel downtime from. This must be specified if you are not using the downtime_id directly.

service = STRING [optional]

If specified, cancel any downtimes on this service.

services_too = BOOL [optional]

If true and you have not specified a service in specific, then we will cancel all downtimes on this host and all of the services it has.

disable_notifications

This disables alert notifications on a host or service. (As an operational note, you might want to schedule downtime instead. Disabling notifications has a habit of leaving things off and people forgetting about it.)

{
  "host": "string",
  "service": "string"
}

Fields

host = STRING [required]

Which host to act on.

service = STRING [optional]

If specified, act on this service.

delete_comment

Deletes comments from a host or service. Can be used to delete all comments or just a particular comment.

{
  "host": "string",
  "service": "string",
  "comment_id": 1234
}

Fields

host = STRING [required]

Which host to act on.

service = STRING [optional]

If specified, act on this service.

comment_id = INTEGER [required]

The ID of the comment you wish to delete. You may set this to -1 to delete all comments on the given host or service.

enable_notifications

This enables alert notifications on a host or service.

{
  "host": "string",
  "service": "string"
}

Fields

host = STRING [required]

Which host to act on.

service = STRING [optional]

If specified, act on this service.

log

Simply returns the most recent 1000 items in the Nagios event log. These are currently unparsed. There is a plan to parse this in the future and return event objects.

status

Simply returns a JSON that contains nagios status objects.

restart_nagios

Restarts the nagios service.

update_host

This method will create/update a nagios configuration file that contains devices.

{
  "file_name": "string",
  "text": "string"
}

Fields

file_name = STRING [required]

File name for the configuration.

text = STRING [required]

Content of the configuration file.

objects

Returns a dict with the key being hostnames and the values being a list of services defined for that host. Use this method to get the contents of the world -- i.e., all hosts and services.

remove_acknowledgement

This method cancels an acknowledgement on a host or service.

{
  "host": "string",
  "service": "string"
}

Fields

host = STRING [required]

Which host to act on.

service = STRING [optional]

If specified, act on this service.

schedule_check

This API lets you schedule a check for a host or service. This also allows you to force a check.

{
  "host": "string",
  "service": "string",
  "check_time": 1234,
  "forced: true,
  "output": "string"
}

Fields

host = STRING [required]

The host to schedule a check for. Required.

service = STRING [optional]

If present, we'll schedule a check on this service at the given time.

all_services = BOOL [optional]

If present, we'll schedule a check on again all services at the given time.

check_time = INTEGER [optional]

Optional, defaults to now. You can specify what time you want the check to be run at.

forced = BOOL [optional]

Optional, defaults to FALSE. When true, then you force Nagios to run the check at the given time. By default, Nagios will only run the check if it meets the standard eligibility criteria.

output = STRING [required]

The plugin output to be displayed in the UI and stored. This is a single line of text, normally returned by checkers.

schedule_downtime

This general purpose method is used for creating fixed length downtimes. This method can be used on hosts and services. You are allowed to specify the author and comment to go with the downtime, too. The JSON parameters are:

{
  "host": "string",
  "duration": 1234,
  "service": "string",
  "services_too": true,
  "author": "string",
  "comment": "string"
}

Fields

host = STRING [required]

Which host to schedule a downtime for. This must be specified.

duration = INTEGER [required]

How many seconds this downtime will last for. They begin immediately and continue for duration seconds before ending.

service = STRING [optional]

If specified, we will schedule a downtime for this service on the above host. If not specified, then the downtime will be scheduled for the host itself.

services_too = BOOL [optional]

If true and you have not specified a service in specific, then we will schedule a downtime for the host and all of the services on that host. Potentially many downtimes are scheduled.

author = STRING [optional]

The name of the author. This is useful in UIs if you want to disambiguate who is doing what.

comment = STRING [optional]

As above, useful in the UI.

The result of this method is a text string that indicates whether or not the downtimes have been scheduled or if a different error occurred. We do not have the ability to get the downtime_id that is generated, unfortunately, as that would require waiting for Nagios to regenerate the status file.

schedule_hostgroup_downtime

This method is used for creating fixed length downtimes on all the hosts belonging to a hostgroup. You are allowed to specify the author and comment to go with the downtime, too. The JSON parameters are:

{
  "hostgroup": "string",
  "duration": 1234,
  "services_too": true,
  "author": "string",
  "comment": "string"
}

Fields

hostgroup = STRING [required]

Which hostgroup to schedule a downtime for. This must be specified.

duration = INTEGER [required]

How many seconds this downtime will last for. They begin immediately and continue for duration seconds before ending.

services_too = BOOL [optional]

If true, then we will schedule a downtime for all the hosts in the hostgroup and all of the services on those hosts. Potentially many downtimes are scheduled.

author = STRING [optional]

The name of the author. This is useful in UIs if you want to disambiguate who is doing what.

comment = STRING [optional]

As above, useful in the UI.

The result of this method is a text string that indicates whether or not the downtimes have been scheduled or if a different error occurred. We do not have the ability to get the downtime_id that is generated, unfortunately, as that would require waiting for Nagios to regenerate the status file.

state

This method takes no parameters. It returns a large JSON object containing all of the active state from Nagios. Included are all hosts, services, downtimes, comments, and other things that may be in the global state object.

submit_result

If you are using passive service checks or you just want to submit a result for a check, you can use this method to submit your result to Nagios.

{
  "host": "string",
  "service": "string",
  "status": 1234,
  "output": "string"
}

Fields

host = STRING [required]

The host to submit a result for. This is required.

service = STRING [optional]

If specified, we will submit a result for this service on the above host. If not specified, then the result will be submitted for the host itself.

status = INTEGER [required]

The status code to set this host/service check to. If you are updating a host's status: 0 = OK, 1 = DOWN, 2 = UNREACHABLE. For service checks, 0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN.

output = STRING [required]

The plugin output to be displayed in the UI and stored. This is a single line of text, normally returned by checkers.

The response indicates if we successfully wrote the command to the log.

Docker

A Docker container is available for convenience. It needs to be run on the same server as the nagios installation.

First determine the location of the status.dat, nagios.log, and nagios.cmd files. Map these files into the Docker container. The container can be started using the following command:

docker run -v /var/lib/nagios3/rw/nagios.cmd:/opt/nagios.cmd \
-v /var/cache/nagios3/status.dat:/opt/status.dat \
-v /var/log/nagios3/nagios.log:/opt/nagios.log \
-p 2337:8080 inventid/nagios-python-api

In the above case, the API will be exposed on port 2337.

Author

Written by Mark Smith [email protected] while under the employ of Bump Technologies, Inc.

Copying

See the LICENSE file for licensing information.

nagios-api's People

Contributors

aichaoxy avatar alexander-n avatar avleen avatar bujo avatar bunjiboys avatar ctrox avatar dblockow-d2dcrc avatar dccmx avatar delowan avatar erik-stephens avatar fessyfoo avatar finkregh avatar ghostsquad avatar gregoo avatar hatchetation avatar hongweipeng avatar jasonmadigan avatar jpsandiego avatar lann avatar lollipopman avatar lozzd avatar mrcrilly avatar neoice avatar neurowinter avatar rincebrain avatar rogierslag avatar scoates avatar woohgit avatar zorkian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nagios-api's Issues

nagios-cli bombs out with a python traceback regardless of command given

Nagios 3.4.1, Python 2.6

# nagios-cli -H localhost -p 8090 hosts Traceback (most recent call last): File "/usr/bin/nagios-cli", line 526, in <module> sys.exit(main(sys.argv[0:])) File "/usr/bin/nagios-cli", line 486, in main temp = api(['objects']) File "/usr/bin/nagios-cli", line 133, in api resobj = loads(res.text) File "/usr/lib64/python2.6/json/__init__.py", line 307, in loads return _default_decoder.decode(s) File "/usr/lib64/python2.6/json/decoder.py", line 319, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) TypeError: expected string or buffer

This is not because the server's not running - contrast:
# nagios-cli -H localhost -p 8085 hosts Failed connecting to nagios-api server

Allow output width setting

nagios-cli appears to limit output to 100 characters wide. This means that some longer service statuses get truncated. It would be nice if the maximum width could be set in the configuration.

It appears that line width is hardcoded in commands/objects.py line 320:

    str(host.services[service].plugin_output)[:48]))

(PS: thanks for nagios-cli - I use it pretty much every day on servers where port-forwarding the Nagios HTTP interface is too cumbersome)

nagios.cmd gets created by nagios-api on nagios death

I found a race condition in send_nagios_command.

  1. Nagios starts
  2. Nagios-api starts, checks for existance of nagios.cmd
  3. Nagios is Stopped
  4. Nagios-api receives an api call, and opens nagios.cmd: At this point nagios-api creates the file.
  5. Nagios is Started - Sees a file where he wants his pipe: Hilarity ensues.

README as Markdown file

Hello,

You should set the README file as a Markdown one : README.md
So that the display can be nice.

Regards.

do not get single service on one host?

hi: http_server do not support for getting single service?
but the comment at the http_service as below.

'''
Get a view of a single service on one host.
Shows all of the variables for the host object.
'''

Compress json output

We're requesting the entire /state every 20 seconds for use with Nagdash (http://github.com/lozzd/Nagdash)... After having a quick look on why it was taking 4-5 seconds to load this, we realised we had 3.7MB of JSON being returned. It would be great to implement gzip HTTP compression for clients that support it to improve this. The 3.7MB state file gzipped is 269kb.

nagios-api | schedule_downtime does not seem to take any actions on the server side

Hello Folks,

I have written a wrapper to run schedule downtime from the client-side. It used to work sometime back (scheduling downtime on nagios server) but at the moment it does not. The wrapper executes the command successfully from the client side as follows:

XXXXXX@XXXXXX:/$ sudo python nagios.py -host XXXXXXXX -D 61 -v Nagios server='NAGIOS_SERVER' found for datacenter='XXX' NAGIOS_HOST - Making HTTP POST request to url='http://NAGIOS_SERVER:NAGIOS_API_PORT/schedule_downtime' with payload='{'duration': 61, 'comment': None, 'host': 'XXXXXXXX', 'author': 'root', 'services_too': True}', headers='{'content-type': 'application/json'}', retries='Retry(total=3, connect=None, read=None, redirect=None)' CLIENT_HOST - Completed successfully HTTP POST call with return status='200' and resp length=77 bytes Nagios downtime_notification completed on host=XXXXXXXX for duration=61 seconds in time=0 secs

I did run it from command line and this is the output
curl -d '{"host": "XXXXXXXX", "duration": 61}' -H 'Content-Type: application/json' http://NAGIOS_SERVER:NAGIOS_API_PORT/schedule_downtime {"content": "External commands not enabled on nagios-api.", "success": false}

May be I m missing something, can you please help figure what could be the issue
Appreciate your prompt reply soon

Thanks

Status.dat Parsing Issue

Hi,

When using the latest nagios (4.1.1) on Ubuntu Precise 64 with Python 2.7.3, I get the following error when trying to start the API:

vagrant@precise64:~/nagios-api$ sudo ./nagios-api -p 3000 -c /usr/local/nagios/var/rw/nagios.cmd -s /usr/local/nagios/var/status.dat  -l /usr/local/nagios/var/nagios.log &
[2] 25705
vagrant@precise64:~/nagios-api$ [2016/07/15 16:49:57] {diesel} INFO:Listening on port 3000, starting to rock and roll!
[2016/07/15 16:49:57] {diesel} WARNING:Starting diesel <hand-rolled select.epoll>
-1
You appear to have handed me a malformed status file - possibly the state retention file. Please check your arguments and try again.
[2016/07/15 16:49:57] {diesel} WARNING:-- SystemExit raised.. exiting main loop --
Cleaning up PID.
Exiting.
Exception KeyError: KeyError(139771800704768,) in <module 'threading' from '/usr/lib/python2.7/threading.pyc'> ignored

[2]-  Done                    sudo ./nagios-api -p 3000 -c /usr/local/nagios/var/rw/nagios.cmd -s /usr/local/nagios/var/status.dat -l /usr/local/nagios/var/nagios.log

I hacked around a bit, and found that this line in ./nagios/core.py was failing:

if line.find("NAGIOS STATE RETENTION FILE") is not -1.0:

It seems that the version of string.find in this python version returns a -1 (non-float) and that caused the API to assume that it was the retention file by mistake. Maybe casting the output would ensure that the result is standardized among versions? Happy to submit a pull request if you'd like.

Thanks!

New version on pypi?

Hi Mark,

Great to see this codebase is still alive and accepting contributions. Any chance of the latest code making it up to Pypi? If not (or not soon), what's the recommended way to get the latest code installed?

Thanks!

Specific Python Version Required?

Is there a specific version of Python required to run this?

I just downloaded the tool (great idea by the way) and tried running it with Python 2.4 and I get a syntax error.

[cbrito@ccpcmb-dt-c1-dqi xb95-nagios-api-4340fd2]$ sudo ./nagios-api -p 20000 -c /usr/local/nagios/var/rw/nagios.cmd File "./nagios-api", line 171 host = reqobj['host'] if 'host' in reqobj else None ^ SyntaxError: invalid syntax

[cbrito@ccpcmb-dt-c1-dqi xb95-nagios-api-4340fd2]$ python - Python 2.4.3 (#1, Sep 21 2011, 19:55:41) [GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2

http://ip:port/state fetches same data even status.dat has been updated by nagios

I am using nagios-api docker . When running it , i get correct status.dat data at first try . For each subsequent call , it shows that old data even though status.data file has been updated . Docker log says :
Exception KeyError: KeyError(140284379903744,) in module 'threading' from '/usr/lib/python2.7/threading.pyc' ignore

Dependencies question

Hi Mark, first of all thank you for creating this great piece of software. You will have a PR coming from me in the future. On to my question...

What is the reason for the greenlet dependency being locked to version 0.3.4? 0.4.12 is latest. If your software can work with >=0.3.4 that might be better for everyone.

Thanks!

Basic HTTP Auth or API key

It would be nice to have a method of restricting access, other than iptables.

I can think of two apparent methods:

Use http basic authentication:

--http-auth-user="" --http-auth-password=""

Use an api key that needs to be added to each request as a GET parameter

--auth-key="sdklfjsdklfjsdaklfjkl"

All requests would have to be like host:8080/cmd?key=sdklfjsdklfjsdaklfjkl

diesel.log has no sublog method

Hello!

Diesel has innovated away their own logging and there's no longer a sublog method on their Logger class (which is just a Twiggy.Logger object).

So ./nagios-api -s ../tmp/nagios/status.dat results in a fatal error, complaining about glog.sublog().

WARNING:Starting diesel <hand-rolled select.epoll>

I thought I would give nagios-api a try today. I got it to start, but received the following warning message:
WARNING:Starting diesel

What does this warning mean and is there something I should do to fix it?

The reason I am posting this is because it seems using nagios-api is causing quite a load on my nagios server, which I suspect is because it is parsing the status.dat file for information. Has any thought been put into possibly using mklivestatus instead of parsing the status.dat file? I would expect using mklivestatus to be much more lightweight.

Latest version of greenlet (0.4.10) causes nagios-api to not start

Problem:

Have been happily running nagios-api for a long time (thank you :) ) using greenlet versions < 0.4.9.

However, greenlet recently updated to 0.4.10, and I built some new machines that used the latest when installed.

Nagios-api no longer starts, producing this error:

fake@somehost:/# sudo python /usr/sbin/nagios-api -p 7654 Traceback (most recent call last): File "/usr/sbin/nagios-api", line 31, in <module> from diesel import Application, Loop, Service, sleep File "/usr/local/lib/python2.7/dist-packages/diesel/__init__.py", line 4, in <module> from core import sleep, Loop, wait, fire, thread, until, Connection, UDPSocket, ConnectionClosed, ClientConnectionClosed, signal File "/usr/local/lib/python2.7/dist-packages/diesel/core.py", line 13, in <module> from greenlet import greenlet ImportError: /usr/local/lib/python2.7/dist-packages/greenlet.so: undefined symbol: _PyTrash_thread_deposit_object

I can confirm that downgrading the version to 0.4.9 enables it to work.

Workaround:

Interestingly, if you use easy_install to install the greenlet 0.4.10 egg, it works. Go figure!! :)

Nagios4

It is possible to use "NAGIOS-API" with Nagios 4 ??
The connection is done well, but no return of the check.
thank you

Needs tests

Besides the obvious, that tests would help catch bugs, it would also help to document usage.

read_log def blocks api requests

read_log loop takes too long to finish on large nagios installations taking up to 5 minutes to complete before answering the api request loop via diesel. Added is a PR that moves the read_log into a thread outside of diesel.

documentation - installation on Ubuntu

Hi,
I would like to share these steps required to install nagios-api on Ubuntu, could you please include them into README

apt-get install python-virtualenv libffi-dev python-dev python-pip python-setuptools
cd ; virtualenv env
~/env/bin/pip install diesel
~/env/bin/pip install requests
cd /opt/ ; git clone https://github.com/zorkian/nagios-api
~/env/bin/python /opt/nagios-api/nagios-api -p 6315 -s /var/cache/nagios3/status.dat -c /var/lib/nagios3/rw/nagios.cmd -l /var/log/nagios3/nagios.log -b 127.0.0.1

1.2.1 Seems broken for pip & easy_install on ubuntu 12.10

Reproduced on a clean Ubuntu 12.04 AWS instance.

sudo pip install nagios-api

Grabs the latest version in pypi, which is currently 1.2.1

Command python setup.py egg_info failed with error code 1
Exception information:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 126, in main
self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 223, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 980, in prepare_files
req_to_install.run_egg_info()
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 216, in run_egg_info
command_desc='python setup.py egg_info')
File "/usr/lib/python2.7/dist-packages/pip/init.py", line 255, in call_subprocess
% (command_desc, proc.returncode))
InstallationError: Command python setup.py egg_info failed with error code 1

If I install 1.2 (via sudo pip install nagios-api==1.2) everything works fine, so it seems like a recent problem.

Looking at the tarball for 1.2.1, it just looks wrong - it contains a usr/local/ path structure inside, rather than just a top-level flat nagios-api-1.2 structure as in the working tarball. Probably an easy fix to unload a new one,

on nagios-api startup, AttributeError: 'NoneType' object has no attribute 'attach_comment'

I'm reasonably confident I'm not calling it wrong.

$ nagios-api -c '/var/nagios/rw/nagios.cmd' -s /var/nagios/retention.dat -l /var/log/nagios/nagios.log -p 8080 [2013/01/04 19:56:50] {diesel} INFO:Listening on port 8080, starting to rock and roll! [2013/01/04 19:56:50] {diesel} WARNING:Starting diesel <hand-rolled select.epoll> [2013/01/04 19:56:50] {diesel} ERROR:-- Unhandled Exception in local loop <<function read_status at 0x1ae0410>> -- Traceback (most recent call last): File "/usr/lib/python2.6/site-packages/diesel/core.py", line 178, in run self.loop_callable(*self.args, **self.kw) File "/usr/bin/nagios-api", line 742, in read_status NAGIOS = Nagios(statusfile) File "/usr/lib/python2.6/site-packages/nagios/core.py", line 21, in __init__ self._update(statusfile) File "/usr/lib/python2.6/site-packages/nagios/core.py", line 81, in _update self.host_or_service(c.host, c.service).attach_comment(c) AttributeError: 'NoneType' object has no attribute 'attach_comment' [2013/01/04 19:56:50] {diesel} WARNING:(Keep-Alive loop <Loop id=1 callable=<function read_status at 0x1ae0410>> died; restarting) [2013/01/04 19:56:50] {diesel} ERROR:-- Unhandled Exception in local loop <<function read_status at 0x1ae0410>> -- Traceback (most recent call last): File "/usr/lib/python2.6/site-packages/diesel/core.py", line 178, in run self.loop_callable(*self.args, **self.kw) File "/usr/bin/nagios-api", line 742, in read_status NAGIOS = Nagios(statusfile) File "/usr/lib/python2.6/site-packages/nagios/core.py", line 21, in __init__ self._update(statusfile) File "/usr/lib/python2.6/site-packages/nagios/core.py", line 81, in _update self.host_or_service(c.host, c.service).attach_comment(c) AttributeError: 'NoneType' object has no attribute 'attach_comment' [2013/01/04 19:56:50] {diesel} WARNING:(Keep-Alive loop <Loop id=1 callable=<function read_status at 0x1ae0410>> died; restarting) [2013/01/04 19:56:50] {diesel} WARNING:-- KeyboardInterrupt raised.. exiting main loop -- [2013/01/04 19:56:50] {diesel} INFO:Ending diesel application

Nagios 3.4.1, Python 2.6, latest Git for nagios-api (898e...bec2)

Logstash json state output

Hello

I'm not able to find a way to parse the json output from the state json output.
I'm try to get information from my centreon installation right into ELK without any luck.
I though you nagios-api could help me to get json output from centreon. it works well but I can't get logstash to parse it :(

thanks for your help.

GET trend data?

I don't think this API currently supports GET calls for trend data from Nagios. Am I correct?

Is there a way to extract trend data (like host > service > status > last 31 days) into JSON?

Thanks!

API stops responding and container produces a lot a weird logs

Hello,

First of all, thanks a lot, what you did is awesome and very useful !
Here are the issues :

  • Sometimes the API stops responding and I do not why.
  • The container produces a lot a weird logs like these ones :

[2016/06/07 14:15:42] {diesel} ERROR|Traceback (most recent call last):\n File "/opt/env/local/lib/python2.7/site-packages/diesel/app.py", line 73, in _main\n File "/opt/env/local/lib/python2.7/site-packages/diesel/hub.py", line 266, in handle_events\n File "/opt/env/local/lib/python2.7/site-packages/diesel/app.py", line 216, in accept_new_connection\n File "/usr/lib/python2.7/socket.py", line 206, in accept\nerror: [Errno 24] Too many open files\n

[2016/06/07 14:15:42] {diesel} ERROR|-- Unhandled Exception rose to main loop --

Thanks a lot !

Trouble building Debian package as there are no test available

Environnement: Debian 7.10 + Sloppy backports (for dh-virtualenv package, 0.10-1~bpo70+1) + libffi-dev required for building as well

At the end of ./build_deb.sh, dh-virtualenv (which is ran by dpkg-buildpackage) tries to launch the tests (setup.py test) but there aren't any and the command exits with a non-zero return code, thus aborting the build process.

Successfully installed nagios-api
Cleaning up...
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: invalid command 'test'
Traceback (most recent call last):
  File "/usr/bin/dh_virtualenv", line 106, in <module>
    sys.exit(main() or 0)
  File "/usr/bin/dh_virtualenv", line 92, in main
    deploy.run_tests()
  File "/usr/lib/python2.7/dist-packages/dh_virtualenv/deployment.py", line 153, in run_tests
    subprocess.check_call([python, 'setup.py', 'test'], cwd=self.sourcedirectory)
  File "/usr/lib/python2.7/subprocess.py", line 511, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/home/gregory/git/nagios-api/debian/nagios-api/usr/share/python/nagios-api/bin/python', 'setup.py', 'test']' returned non-zero exit status 1
make: *** [binary] Error 1
dpkg-buildpackage: error: fakeroot debian/rules binary gave error exit status 2

Adding --no-test to debian/rules seems to solve the problem

$ cat debian/rules
#!/usr/bin/make -f

%:
        dh $@ --with python-virtualenv --no-test
Successfully installed nagios-api
Cleaning up...
   dh_usrlocal -O--no-test
   dh_link -O--no-test
   dh_compress -O--no-test
[...]
$ file dist/nagios-api_1.2.2-1_amd64.deb
dist/nagios-api_1.2.2-1_amd64.deb: Debian binary package (format 2.0)

Spaces in hostnames

When I call the API like this:

/host/Test_Server_1 the API responds fine.

however if I try this:

/host/Test Server 1

The API responds with {"content": "Invalid request URI", "success": false}

Can you please advise how i can get details of hostnames with spaces in the name?

Thanks

Fails when performance data has Infinity value

/dev[2015/09/22 19:11:54] {diesel} ERROR|-- Unhandled Exception in local loop <<function read_status at 0x3288140>> --
Traceback (most recent call last):
File "/usr/local/lib/python2.6/site-packages/diesel/core.py", line 195, in run
self.loop_callable(_self.args, *_self.kw)
File "/srv/nagios-api/nagios-api", line 833, in read_status
NAGIOS = Nagios(statusfile)
File "/srv/nagios-api/nagios/core.py", line 21, in init
self._update(statusfile)
File "/srv/nagios-api/nagios/core.py", line 72, in _update
for obj in next_stanza(f):
File "/srv/nagios-api/nagios/core.py", line 58, in next_stanza
if (n_val == int(n_val)):
OverflowError: cannot convert float infinity to integer
[2015/09/22 19:11:54] {diesel} WARNING|(Keep-Alive loop <Loop id=1 callable=<function read_status at 0x3288140>> died; restarting)

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.