Last active
February 7, 2019 03:39
-
-
Save hoangdh/16a295430ea3a929cb74d39311c823cb to your computer and use it in GitHub Desktop.
Check HTTP code status using Nagios/check_mk plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| SERVER=$1 | |
| STATUS=$(curl -sL -o /dev/null -w "%{http_code}" $SERVER) | |
| case $STATUS in | |
| 200) | |
| echo "$SERVER is still running." | |
| exit 0 | |
| ;; | |
| *) | |
| echo "$SERVER is not running." | |
| exit 1 | |
| esac | |
| # Using python: https://stackoverflow.com/questions/645312/what-is-the-quickest-way-to-http-get-in-python | |
| ### | |
| # #!/bin/bash | |
| # domain="$1" | |
| # code=`curl -s -o /dev/null -I -w "%{http_code}" $domain -Lk --connect-timeout 30` | |
| # if [ "$code" != "200" ] | |
| # then | |
| # echo "$domain - HTTP code: $code" | |
| # exit 2 | |
| # else | |
| # echo "$domain - HTTP code: $code" | |
| # exit 0 | |
| # fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment