nagios , alert of grafana
nagios , alert of grafana
hello , i want configure nagios for get alert of grafana , but i Don't find information how i can do that , please help
-
- Posts: 5324
- Joined: Wed Aug 22, 2018 4:39 pm
- Location: saint paul
Re: nagios , alert of grafana
HI,
Do you mean alerts or performance graphs? In most cases, it's performance graphs.
Take a look at: https://support.nagios.com/kb/article/n ... u-802.html
Do you mean alerts or performance graphs? In most cases, it's performance graphs.
Take a look at: https://support.nagios.com/kb/article/n ... u-802.html
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: nagios , alert of grafana
Thanks for your reply , i need a plugin for nagios so that it can check if there are alerts in grafana , if yes nagios gets this alerts thanks so much
Re: nagios , alert of grafana
I usually put this code into an script into /usr/local/bin/. If this is confusing to you, refer on this link https://linuxboss.wordpress.com/2015/06 ... afana-how/
portable propane generator top kitchen cabinets top rated personal injury lawyer
portable propane generator top kitchen cabinets top rated personal injury lawyer
Re: nagios , alert of grafana
Thanks ,but it's not works
Re: nagios , alert of grafana
What versions of Grafana and Nagios Core are you using?
With Nagios XI, through the REST API, you could configure a generic webhook in Grafana to feed information into an event handler. Not sure there's anything equivalent in Nagios Core unless you've got NRDP set up. To get the full content of every Grafana alert into Nagios Core, an event handler of some sort is really the way to go.
Here's a quick Bash script I ginned up as a Nagios plugin that hits the Grafana REST API's alerts endpoint with curl to grab the active alerts, and uses grep+wc to count the number of active alerts:
Should just need to edit the GRAFANA_ variables to match your Grafana installation. Gets the "works on my machine" gold star of approval against Grafana 7.4.5; YMMV.
You could probably do clever things with cron, jq, and the Nagios Core external commands file to implement some sort of pull method rather than a push method. I'd recommend a push method in this case; Grafana does that pretty well out of the box.
With Nagios XI, through the REST API, you could configure a generic webhook in Grafana to feed information into an event handler. Not sure there's anything equivalent in Nagios Core unless you've got NRDP set up. To get the full content of every Grafana alert into Nagios Core, an event handler of some sort is really the way to go.
Here's a quick Bash script I ginned up as a Nagios plugin that hits the Grafana REST API's alerts endpoint with curl to grab the active alerts, and uses grep+wc to count the number of active alerts:
Code: Select all
GRAFANA_URL='http://localhost:3000'
GRAFANA_USERNAME='your_username_here'
GRAFANA_PASSWORD='your_password_here'
CURL_COMMAND=$(curl -XGET -s --show-error -u "$GRAFANA_USERNAME:$GRAFANA_PASSWORD" "$GRAFANA_URL/api/alerts" 2>&1)
CURL_STATUS=$?
if [ $CURL_STATUS -ne 0 ]; then
echo "UNKNOWN - Error calling Grafana API: ${CURL_COMMAND}"
exit 3;
fi
if [[ "$CURL_COMMAND" == *\"message\":* ]]; then
echo "UNKNOWN - Grafana API returned: $CURL_COMMAND"
exit 3;
fi
COUNT_COMMAND=$(grep -o '"id":[0-9]*,' <<< ${CURL_COMMAND} | wc -l)
if [ "$COUNT_COMMAND" -eq "0" ]; then
echo "OK - No Grafana alerts found.";
exit 0;
else
echo "CRITICAL - ${COUNT_COMMAND} alerts found in Grafana."
exit 2;
fi
echo "UNKNOWN - An unexpected error occurred in the script."
exit 3;
Code: Select all
## invalid connection
# sh check_grafana.sh
UNKNOWN - Error calling Grafana API: curl: (7) Failed to connect to localhost port 3000: Connection refused
# sh test.sh
CRITICAL - 1 alerts found in Grafana.
# sh test.sh
OK - No Grafana alerts found.
## with invalid creds
# sh test.sh
UNKNOWN - Grafana API returned: {"message":"invalid username or password"}
# echo $?
3
Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/
Re: nagios , alert of grafana
thanks so much for your help , thanks
i did something wrong
GRAFANA_URL='http://llsndn3b.sandbox.gcloud.belgium.be/'
GRAFANA_USERNAME='admin'
GRAFANA_PASSWORD='student'
CURL_COMMAND=$(curl -XGET -s --show-error -u "$GRAFANA_USERNAME:$GRAFANA_PASSWORD" "$GRAFANA_URL/api/alerts" 2>&1)
CURL_STATUS=$?
if [ $CURL_STATUS -ne 0 ]; then
echo "UNKNOWN - Error calling Grafana API: ${CURL_COMMAND}"
exit 3;
fi
if [[ "$CURL_COMMAND" == *\"message\":* ]]; then
echo "UNKNOWN - Grafana API returned: $CURL_COMMAND"
exit 3;
fi
COUNT_COMMAND=$(grep -o '"id":[0-9]*,' <<< ${CURL_COMMAND} | wc -l)
if [ "$COUNT_COMMAND" -eq "0" ]; then
echo "OK - No Grafana alerts found.";
exit 0;
else
echo "CRITICAL - ${COUNT_COMMAND} alerts found in Grafana."
exit 2;
fi
echo "UNKNOWN - An unexpected error occurred in the script."
exit 3;
-------------------------------------------------------------------------------
in nagios :
ssh check_alerts_grafana.sh
his give my
check_alerts_grafana.sh: line 9: [: missing']'
wc: invalid option --'1'
check_alerts_grafana.sh: line 20 [: : integer expresion expected
CRITICAL - ALERTS found in grafana
what you thinks where's problem ?
thanks you so so much for you help ,
i did something wrong
GRAFANA_URL='http://llsndn3b.sandbox.gcloud.belgium.be/'
GRAFANA_USERNAME='admin'
GRAFANA_PASSWORD='student'
CURL_COMMAND=$(curl -XGET -s --show-error -u "$GRAFANA_USERNAME:$GRAFANA_PASSWORD" "$GRAFANA_URL/api/alerts" 2>&1)
CURL_STATUS=$?
if [ $CURL_STATUS -ne 0 ]; then
echo "UNKNOWN - Error calling Grafana API: ${CURL_COMMAND}"
exit 3;
fi
if [[ "$CURL_COMMAND" == *\"message\":* ]]; then
echo "UNKNOWN - Grafana API returned: $CURL_COMMAND"
exit 3;
fi
COUNT_COMMAND=$(grep -o '"id":[0-9]*,' <<< ${CURL_COMMAND} | wc -l)
if [ "$COUNT_COMMAND" -eq "0" ]; then
echo "OK - No Grafana alerts found.";
exit 0;
else
echo "CRITICAL - ${COUNT_COMMAND} alerts found in Grafana."
exit 2;
fi
echo "UNKNOWN - An unexpected error occurred in the script."
exit 3;
-------------------------------------------------------------------------------
in nagios :
ssh check_alerts_grafana.sh
his give my
check_alerts_grafana.sh: line 9: [: missing']'
wc: invalid option --'1'
check_alerts_grafana.sh: line 20 [: : integer expresion expected
CRITICAL - ALERTS found in grafana
what you thinks where's problem ?
thanks you so so much for you help ,