Kategorien
Nagios Windows

Prüfen von Backup Dateien mit Nagios

NagiosMit nrpe_nt (Nagios Remote Plugin Executor) lassen sich auch verschiedene Dienste auf Windows Servern überprüfen.

In diesem Beispiel wird mit dem nrpe_nt in Kombination mit einem vb Script (check_backupfile.vbs) die Existenz eines Backups geprüft.

check_backupfile.vbs

Download check_backupfile.vbs

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' check_backupfile.vbs - Nagios NRPE plugin to check file size and age
'
' Send bug reports to fk fk@kworx.de (https://www.kworx.de)
' ' The script must always be run with 'cscript //NoLogo'!
'
' Example command definition for nrpe_nt
' command[check_backupfile]=%SYSTEMROOT%\system32\cscript.exe //NoLogo
'                    "c:\nrpe_nt\check_backupfile.vbs" "c:\backup.zip"
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright 2006 Fadil Karalic fk@kworx.de (https://www.kworx.de)
'
' 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 3 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, see .
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
Option Explicit
 
' return codes
Const RETURN_OK=0
Const RETURN_WARNING=1
Const RETURN_CRITICAL=2
Const RETURN_UNKNOWN=3
 
Dim file, minsize, maxage
Dim fileage, filemodified, filesize
Dim wso, fso, oFile
Dim WARN, WARNMESSAGE
 
' force cscript
set wso=CreateObject("WScript.Shell")
If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then
    wso.Run "cscript //NoLogo """ & WScript.ScriptFullName & """", 1, False
    WScript.Quit
End If
 
' check argument
if wscript.Arguments.Count<>3 then
        WScript.echo "usage:" & vbCrLf & _
                " cscript //NoLogo check_backupfile.vbs" & _
                "   "
        WScript.echo "example:" & vbCrLf & _
                " cscript //NoLogo check_backupfile.vbs c:\backup.zip 10 24"
        WScript.echo vbCrLf & " Status is CRITICAL if the file " & _
                " c:\backup.zip is missing." & vbCrLf & _
                " Status is WARNING if the file is smaller than 10MB" & _
                " or older than 24h."
        Wscript.Quit(RETURN_UNKNOWN)
end if
 
file=wscript.Arguments(0)
minsize=cint(wscript.Arguments(1))
maxage=cint(wscript.Arguments(2))
 
' check if file exists
set fso=CreateObject("Scripting.FileSystemObject")
 
if not fso.FileExists(file) then
        ' file ist missing so there is no need to continue
        WScript.echo "CRITICAL - File " & file & " not found!"
        Wscript.Quit(RETURN_CRITICAL)
end if
 
WARN=0
WARNMESSAGE=""
 
'check file size
set oFile=fso.getfile(file)
filesize=cint(oFile.size / 1024 / 1024)
if (filesize < minsize) then
        WARN=WARN+1
end if
WARNMESSAGE=WARNMESSAGE & " size=" & filesize & "MB (required >=" & minsize & "MB)"
 
' check file age
filemodified=oFile.DateLastModified
fileage=DateDiff("h", filemodified, now())
 
if (fileage > maxage) then
        ' file to old
        WARN=WARN+1
end if
WARNMESSAGE=WARNMESSAGE & " age=" & fileage & "h (required < =" & maxage & "h)"
 
' and finally return a message
if (WARN=0) then
        WScript.echo "OK - File " & oFile.name & WARNMESSAGE & "."
        Wscript.Quit(RETURN_OK)
else
        WScript.echo "WARNING - File " & oFile.name & WARNMESSAGE & "."
        Wscript.Quit(RETURN_WARNING)
end if

Das Script benötigt drei Parameter die beim Aufruf übergeben werden müssen.
check_backupfile.vbs Dateiname Dateigröße Dateialter
Der Dateiname muss inclusive absolutem Pfad mit angegeben werden.
Die Dateigröße wird in MB angegeben.
Das Dateialter wird in Stunden angegeben.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert