Page 1 of 1

Loggin to Nagios from script in python

Posted: Tue Aug 07, 2018 7:55 pm
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.

Re: Loggin to Nagios from script in python

Posted: Wed Aug 08, 2018 8:42 am
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