Unable to fetch Availability report for last 7 days from Nagios core using script
Posted: Fri Feb 20, 2026 3:33 am
Hello,
Good day.
I am trying to get Availability report of last 7 days from Nagios core. I got a script to automate this report and i have placed it under the below path:
/usr/local/nagios/libexec
Script:
#!/bin/bash
NAGIOS_URL="http://nagios-server/nagios/cgi-bin/avail.cgi"
NAGIOS_USER="username"
NAGIOS_PASS="password"
RECIPIENT_EMAIL="email address"
REPORT_FILE="availability_report.csv"
START_TIME=$(date -d "7 days ago" +%s)
END_TIME=$(date +%s)
# Fetch the availability report in a "dump" (CSV-like) format
# and save it to a file.
curl -s -u "$username:$password" "$http://nagios-server/nagios/cgi-bin/ava ... utput=dump" > "$REPORT_FILE"
# Check if the curl command was successful
if [ $? -eq 0 ] && [ -s "$REPORT_FILE" ]; then
echo "Nagios availability report generated. Sending email..."
# Send the email with the report as an attachment
# The mail command varies by system. This example uses a common syntax.
# Adjust the 'mail' command as needed for your specific system.
echo "Please find the last 7 days Nagios availability report attached." | mail -s "Nagios Availability Report (Last 7 Days)" -A "$REPORT_FILE" "$RECIPIENT_EMAIL"
echo "Email sent to $RECIPIENT_EMAIL."
else
echo "Failed to generate report or report is empty."
fi
# Clean up the report file
rm "$REPORT_FILE"
Output:
I am getting excel over mail but data is not getting displayed. I have tried all the possibilities but no luck.
Please find the below output file over mail which i am receiving:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Unauthorized</title>
</head><body>
<h1>Unauthorized</h1>
<p>This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g. bad password) or your
browser doesn't understand how to supply
the credentials required.</p>
<hr>
<address>Apache/2.4.58 (Ubuntu) Server at inisnagios01 Port 80</address>
</body></html>
I have verified credentials also but still having issue. Kindly please check and help me in solving this issue.
Thanks in advance.
Srinija.
Good day.
I am trying to get Availability report of last 7 days from Nagios core. I got a script to automate this report and i have placed it under the below path:
/usr/local/nagios/libexec
Script:
#!/bin/bash
NAGIOS_URL="http://nagios-server/nagios/cgi-bin/avail.cgi"
NAGIOS_USER="username"
NAGIOS_PASS="password"
RECIPIENT_EMAIL="email address"
REPORT_FILE="availability_report.csv"
START_TIME=$(date -d "7 days ago" +%s)
END_TIME=$(date +%s)
# Fetch the availability report in a "dump" (CSV-like) format
# and save it to a file.
curl -s -u "$username:$password" "$http://nagios-server/nagios/cgi-bin/ava ... utput=dump" > "$REPORT_FILE"
# Check if the curl command was successful
if [ $? -eq 0 ] && [ -s "$REPORT_FILE" ]; then
echo "Nagios availability report generated. Sending email..."
# Send the email with the report as an attachment
# The mail command varies by system. This example uses a common syntax.
# Adjust the 'mail' command as needed for your specific system.
echo "Please find the last 7 days Nagios availability report attached." | mail -s "Nagios Availability Report (Last 7 Days)" -A "$REPORT_FILE" "$RECIPIENT_EMAIL"
echo "Email sent to $RECIPIENT_EMAIL."
else
echo "Failed to generate report or report is empty."
fi
# Clean up the report file
rm "$REPORT_FILE"
Output:
I am getting excel over mail but data is not getting displayed. I have tried all the possibilities but no luck.
Please find the below output file over mail which i am receiving:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Unauthorized</title>
</head><body>
<h1>Unauthorized</h1>
<p>This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g. bad password) or your
browser doesn't understand how to supply
the credentials required.</p>
<hr>
<address>Apache/2.4.58 (Ubuntu) Server at inisnagios01 Port 80</address>
</body></html>
I have verified credentials also but still having issue. Kindly please check and help me in solving this issue.
Thanks in advance.
Srinija.