nagios , alert of grafana
Posted: Tue Mar 09, 2021 4:19 pm
hello , i want configure nagios for get alert of grafana , but i Don't find information how i can do that , please help ![Neutral :|](./images/smilies/icon_neutral.gif)
![Neutral :|](./images/smilies/icon_neutral.gif)
Support for Nagios products and services
https://support.nagios.com/forum/
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