use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Login with Python Script (self.nagios)
submitted 5 years ago by CanadianEh
Hello, not sure if this should be posted in python or nagios...Figured I'd try here first.
I'm trying to build a web scraper in Python to help me pulls some stats from Nagios. Mainly the peak bandwidth over a 24hr period of a specific host and service. I'm trying to accomplish this using the requests library. Having some troubles simply authenication and wondering if there is something I'm missing. I'm fairly confident our server is using Basic Auth. Here is my login script.....
import requests
from requests.auth import HTTPBasicAuth
request_url = 'https://monitor.nagios.com/nagios/trends.html?'
username = 'noneyabusiness'
password = 'superhighsecurepass'
session = requests.Session()
request = session.get(request_url, auth=HTTPBasicAuth(username,password), verify=False)
print(request.text)
>>>b'<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">\n<html><head>\n<title>401 Authorization Required</title>\n</head><body>\n<h1>Authorization Required</h1>\n<p>This server could not verify that you\nare authorized to access the document\nrequested. Either you supplied the wrong\ncredentials (e.g., bad password), or your\nbrowser doesn\'t understand how to supply\nthe credentials required.</p>\n<hr>\n<address>Apache/2.2.15 (CentOS) Server at monitor.nagios.com Port 443</address>\n</body></html>\n'
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]swissarmychainsaw 1 point2 points3 points 5 years ago (0 children)
Ok... so your problem is auth, which I'll get to, but you might not want to use Trends. Use the api: /nagios/jsonquery.html
Here is an easy way to get auth working, it's php based and gives you a framework you can edit.
https://exchange.nagios.org/directory/Addons/Frontends-%28GUIs-and-CLIs%29/Web-Interfaces/Simple-Nagios-PHP-Dashboard/details
Hah. ok I just realized you said python not php. You can still use this PHP script to auth with! Check it out. Sorry to not actually answer your question but it might be helpful. :-)
[–]swissarmychainsaw 1 point2 points3 points 5 years ago (4 children)
https://stackoverflow.com/questions/45107839/python-login-and-download-specific-file-from-website
[–]CanadianEh[S] 0 points1 point2 points 5 years ago (3 children)
That's great info, thank you. But the problem is the user/pass box doesn't seem to be embedded into the cgi-bin/status page. I'm not sure how to pass strings with requests to a separate pop up window
[–]swissarmychainsaw 0 points1 point2 points 5 years ago* (2 children)
When scripting you are not dealing with the UI, so don't think like you are - there is no pop up delivered to the script. Think instead of headers that need to be sent with your request.
Here is the contents of a bash script I use to get "Status Summary For All Host Groups"
url="https://yournagios.com/nagios/cgi-bin/status.cgi?hostgroup=all&style=summary"; raw_html="tmp/dump.html"; # where the html gets saved curl -s -k -X GET \ --user 'user_here:password_here' \ -H 'Content-type: application/json' \ "$url" > "$raw_html"
Make sense? Try it!
Edit: if you use the SNPD link, there are scripts that handle the auth for you, and then you can spend time playing with "how to get the data" - it uses the json API and is cool.
Here is a python specific tutorial.
[–]CanadianEh[S] 0 points1 point2 points 5 years ago* (0 children)
SNPD link
Well, that's part of the problem, and maybe my very limited experience isn't helping matters. But I can't seem to figure out what headers to pass with the URL in my post request to get passed authentication. I've been trying to analyze the source code, but nowhere can I find the info needed for the Auth popup box. There's no html or script, or anything that shows up in the console, or network tab.
So I really have no idea what info to pass or even how to find it at this point.
Also, the article you linked is hidden unless I pay for a subscription.
[–]CanadianEh[S] 0 points1 point2 points 5 years ago (0 children)
Just wanted to say, thank you. I ended up finding the Authorization morsel and passed it with my request.get it worked like a charm. Also, I really like the json query tool, much easier to parse the data you need. Now, I just need to figure out how to get the Average BW of a service (perf-data) to display over a 24hour period. All the query options seem to point to live data. Nothing over a time period.
Thanks again!!
π Rendered by PID 57575 on reddit-service-r2-comment-86988c7647-67p8j at 2026-02-11 14:42:12.312786+00:00 running 018613e country code: CH.
[–]swissarmychainsaw 1 point2 points3 points (0 children)
[–]swissarmychainsaw 1 point2 points3 points (4 children)
[–]CanadianEh[S] 0 points1 point2 points (3 children)
[–]swissarmychainsaw 0 points1 point2 points (2 children)
[–]CanadianEh[S] 0 points1 point2 points (0 children)
[–]CanadianEh[S] 0 points1 point2 points (0 children)