November 7, 2018 at 6:22 pm
Hello Guys
I run Nagios Core 4.3.4 to check my systems
I found the vbs script that will report back the database size via a Nagios NRPE check.
'
' Check_SQLDBSize.vbs v1.1
'
' Nagios Plugin for checking SQL DB Size
' Tested with NSClient++ v0.4.1.105, Nagios Core 4.0.8 and SQL Server 2008 Express
'
' Author: Gregor Blaj
' Email: gregor[at]nzsystems[dot]com
' Created on: 29/04/2015
'
' Credit to
' https://gallery.technet.microsoft.com/scriptcenter/a6a9d2a4-705f-4e37-86db-33caca7473cb
' http://www.codeproject.com/Tips/469070/SQL-Server-Get-All-Databases-Size
'
' Change Log
' 1.1: Exclude Log from DB size
'
Const adOpenStatic = 3
Const adLockOptimistic = 3Dim dbserver : dbserver = WScript.Arguments.Item(0)
Dim dbname : dbname = WScript.Arguments.Item(1)
Dim dbwarn : dbwarn = cint(WScript.Arguments.Item(2))
Dim dbcrit : dbcrit = cint(WScript.Arguments.Item(3))
'Dim dbuser : dbuser = WScript.Arguments.Item(4)
'Dim dbpwd : dbpwd = WScript.Arguments.Item(5)
Dim dbsize
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open _
"Provider=SQLOLEDB;Data Source=" & dbserver & ";" & _
"Trusted_Connection=Yes;Initial Catalog=" & dbname & ";" ' & _
' "User ID=sa;Password=password;"objRecordSet.Open "SELECT d.name, ROUND(SUM(mf.size) * 8 / 1024, 0) Size_MBs FROM sys.master_files mf INNER JOIN sys.databases d ON d.database_id = mf.database_id WHERE d.database_id > 4 AND d.name='" & dbname & "' AND type_desc <> 'Log' GROUP BY d.name", _
objConnection, adOpenStatic, adLockOptimisticWhile NOT objRecordSet.EOF
For Each field In objRecordSet.Fields
dbsize = field.Value
next
objRecordSet.MoveNext
Wend
if dbsize > dbcrit then
wscript.echo "CRITICAL: " & ucase(dbname) & " database size is " & dbsize & " MB."
exitcode = 2
elseif dbsize > dbwarn then
wscript.echo "WARNING: " & ucase(dbname) & " database size is " & dbsize & " MB."
exitcode = 1
else
wscript.echo "OK: " & ucase(dbname) & " database size is " & dbsize & " MB."
exitcode = 0
end if
wscript.quit exitcode
I modified the script the password of the sa account.
My Nagios command is
:/usr/local/nagios/etc/objects# /usr/lib/nagios/plugins/check_nrpe -t 50 -H TGCS016 -c check_sqldbsize -a 'TGCS016\WSUSSQL SUSDB 8000 5000'
C:\Program Files\NSClient++\scripts\check_sqldbsize.vbs(33, 1) Microsoft OLE DB Provider for SQL Server: Cannot open database "SUSDB" requested by the login. The login failed.
If I run the command from the sql server it runs it is just a remote connection that fails
C:\Program Files\NSClient++\scripts>cscript check_sqldbsize.vbs tgcs016\wsussql
susdb 5000 9000
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
OK: SUSDB database size is 3757 MB.
I created a logon on sql named Nagios but that did not work either.
SA account is not the dbowner on the susdb database.
Any ideas?
Thank you
Tom
Viewing 0 posts
You must be logged in to reply to this topic. Login to reply