Loggin to Nagios from script in python

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
solo_0684
Posts: 3
Joined: Fri Sep 08, 2017 3:52 pm

Loggin to Nagios from script in python

Post by solo_0684 »

Hello I am trying to loggin in nagios since a script made in python with this code:

import sys
import requests
URL = 'http://XXX.XXX.XXX.48/nagiosxi/login.php'
client = requests.session()
client.get(URL)
payload = {
'username': 'my_user',
'password': 'my_pass',
'page': 'auth',
'pageopt': 'login',
'debug': ''
}
r = client.post(URL, data=payload, headers=dict(Referer=URL))
print r.text

But when I run it, I only get: "NSP: Sorry Dave, I can't let you do that"

I want to loggin this way because I want check with a script all the Actions set for each service and I have more than 12000 services, that is a lot of work if I do it handly.

So I do not know if there is a way to do it eaiser.

Thanks in advance.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Loggin to Nagios from script in python

Post by scottwilkerson »

This would require you grab the hidden nsp value and other hidden form elements then submit with that.

A better method to get info about the hosts and services would be to use the builtin API with instructions under Help -> REST API Docs
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked