nagios , alert of grafana

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Elamrani
Posts: 5
Joined: Tue Mar 09, 2021 4:12 pm

nagios , alert of grafana

Post by Elamrani »

hello , i want configure nagios for get alert of grafana , but i Don't find information how i can do that , please help :|
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: nagios , alert of grafana

Post by benjaminsmith »

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
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!
Elamrani
Posts: 5
Joined: Tue Mar 09, 2021 4:12 pm

Re: nagios , alert of grafana

Post by Elamrani »

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
Connorrr
Posts: 1
Joined: Tue Mar 16, 2021 7:41 am

Re: nagios , alert of grafana

Post by Connorrr »

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
Elamrani
Posts: 5
Joined: Tue Mar 09, 2021 4:12 pm

Re: nagios , alert of grafana

Post by Elamrani »

Thanks ,but it's not works :cry:
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: nagios , alert of grafana

Post by mcapra »

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:

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;
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.

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
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.
Former Nagios employee
https://www.mcapra.com/
Elamrani
Posts: 5
Joined: Tue Mar 09, 2021 4:12 pm

Re: nagios , alert of grafana

Post by Elamrani »

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 ,
Locked