From 05899f71f0fb204b7e70c93f95ea8e68322fba11 Mon Sep 17 00:00:00 2001 From: Elyrith Date: Tue, 4 Jun 2013 17:35:12 -0400 Subject: [PATCH 1/4] Added PERFDATA to put Nagios Performance Data when viewing service details. --- check_md5.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/check_md5.sh b/check_md5.sh index 1db50cf..d83c158 100755 --- a/check_md5.sh +++ b/check_md5.sh @@ -103,7 +103,7 @@ while [[ -n "$1" ]]; do --file) if [[ -z "$2" ]]; then - printf "\nOption $1 requires an argument\n" + printf "\nOption $1 requires an argument\n | Option $1 requires an argument" print_help exit $STATE_UNKNOWN fi @@ -113,7 +113,7 @@ while [[ -n "$1" ]]; do --md5) if [[ -z "$2" ]]; then - printf "\nOption $1 requires an argument\n" + printf "\nOption $1 requires an argument\n | Option $1 requires an argument" print_help exit $STATE_UNKNOWN fi @@ -122,7 +122,7 @@ while [[ -n "$1" ]]; do ;; *) - printf "\nInvalid option $1" + printf "\nInvalid option $1 | Invalid option $1" print_help exit $STATE_UNKNOWN ;; @@ -135,14 +135,14 @@ done if [[ -z "$file" ]]; then # No file specified - printf "\nNo file specified" + printf "\nNo file specified | No file specified" print_help exit $STATE_UNKNOWN fi if [[ -z "$md5" ]]; then # No MD5 sum specified - printf "\nNo MD5 sum specified" + printf "\nNo MD5 sum specified | No MD5 sum specified" print_help exit $STATE_UNKNOWN fi @@ -155,17 +155,17 @@ filesum=`md5sum ${file} | awk '{print $1}'` #Compare the MD5 on the file against the sum we provided if [[ "$filesum" == "$md5" ]]; then - printf "$file - MD5 OK\n" + printf "MD5 OK - $file\n | MD5 is $md5" exit $STATE_OK #See if we wanted a warning instead of a critical elif [[ "$warning" == "yes" ]]; then - printf "$file - MD5 WARNING\n" + printf "MD5 WARNING - $file\n | MD5 does not match on file $file" exit $STATE_WARNING #Critical else - printf "$file - MD5 CRITICAL\n" + printf "MD5 CRITICAL - $file\n | MD5 does not match on file $file" exit $STATE_CRITICAL fi From 653c4c227cef12e62ca83cc1aaf059a0743cea32 Mon Sep 17 00:00:00 2001 From: Elyrith Date: Tue, 4 Jun 2013 17:35:49 -0400 Subject: [PATCH 2/4] Update README and add clone for sha512. --- README | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) mode change 100644 => 100755 README diff --git a/README b/README old mode 100644 new mode 100755 index 30131fd..af4b9c9 --- a/README +++ b/README @@ -1,10 +1,12 @@ -check_md5 +check_md5 and check_sha512 A Nagios plugin written in Bash to check the MD5 sum of a single file. In case the files MD5 change the plugin issues a critical state. This behavior can be changed by using a --warning argument, so that only a warning state is issued. +The new check_sha512.sh checks does the exact same thing except it uses sha512sum. +Replace the --md5 flag with --sha512. Options: -h From 9949d52e4b15645532b4fe5870c3f9ac4ee009be Mon Sep 17 00:00:00 2001 From: Elyrith Date: Tue, 4 Jun 2013 17:40:02 -0400 Subject: [PATCH 3/4] Add my name to Author as a contributor. --- check_sha512.sh | 172 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100755 check_sha512.sh diff --git a/check_sha512.sh b/check_sha512.sh new file mode 100755 index 0000000..5396466 --- /dev/null +++ b/check_sha512.sh @@ -0,0 +1,172 @@ +#!/bin/bash + +################################################################################ +# # +# Copyright (C) 2012 Jack-Benny Persson # +# # +# This program is free software; you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation; either version 2 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program; if not, write to the Free Software # +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +# # +################################################################################ + +############################################################################### +# # +# Nagios plugin to monitor a single files SHA512 sum. In case of mismatch # +# the plugin exit with a CRICITAL error code. This behavior can be changed # +# with the --warning argument. # +# Written in Bash (and uses sed & awk). # +# # +############################################################################### + + +VERSION="1.1" +AUTHOR="(c) 2012 Jack-Benny Persson (jack-benny@cyberinfo.se), modified for SHA512 by Ryan Loudfoot (elyrith@gmail.com)" + +# Exit codes +STATE_OK=0 +STATE_WARNING=1 +STATE_CRITICAL=2 +STATE_UNKNOWN=3 + +shopt -s extglob + +#### Functions #### + +# Print version information +print_version() +{ + printf "\n\n$0 - $VERSION\n" +} + +#Print help information +print_help() +{ + print_version + printf "$AUTHOR\n" + printf "Monitor the SHA512 checksum of a single file\n" +/bin/cat < Date: Tue, 4 Jun 2013 18:00:47 -0400 Subject: [PATCH 4/4] Add repo URL. --- check_md5.sh | 4 +++- check_sha512.sh | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/check_md5.sh b/check_md5.sh index d83c158..cbefe88 100755 --- a/check_md5.sh +++ b/check_md5.sh @@ -27,9 +27,11 @@ # with the --warning argument. # # Written in Bash (and uses sed & awk). # # # +# The latest version of check_md5.sh and check_sha512.sh can be found at: # +# https://github.com/jackbenny/check_md5 # +# # ############################################################################### - VERSION="1.1" AUTHOR="(c) 2012 Jack-Benny Persson (jack-benny@cyberinfo.se)" diff --git a/check_sha512.sh b/check_sha512.sh index 5396466..27d8559 100755 --- a/check_sha512.sh +++ b/check_sha512.sh @@ -27,9 +27,11 @@ # with the --warning argument. # # Written in Bash (and uses sed & awk). # # # +# The latest version of check_md5.sh and check_sha512.sh can be found at: # +# https://github.com/jackbenny/check_md5 # +# # ############################################################################### - VERSION="1.1" AUTHOR="(c) 2012 Jack-Benny Persson (jack-benny@cyberinfo.se), modified for SHA512 by Ryan Loudfoot (elyrith@gmail.com)"