SQL Database Size check not working

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
kwhogster
Posts: 644
Joined: Wed Oct 14, 2015 6:51 pm
Location: Wood Ridge NJ USA
Contact:

SQL Database Size check not working

Post by kwhogster »

Nagios Core 4.3.4
Nsclient 4.3
Windows 2012 R2 Server with SQL 2012 Enterprise
Windows 2012 R2 Server with SQL 2014 Enterprise

Setting up this plugging check_sqldbsize.vbs

running the command from the Nagios server

root@tgcs017:/usr/local/nagios/etc/objects/windowsservers# /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: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.

Code: Select all

define command {
        command_name    check_sqldbsize
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -t 120 -c check_sqldbsize -a $ARG1$ $ARG2$ $ARG3$ $ARG4$
        }

Nsclient.ini

Code: Select all

; Check SQL DB Size
check_sqldbsize=c:\\windows\\system32\\cscript.exe //NoLogo scripts\\check_sqldbsize.vbs  $ARG1$ $ARG2$ $ARG3$ $ARG4$ 
Running the vbs script from the server works

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.


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.

Is this a security issue? Which account is the Nagios server using to pass the command over?

Or is it something else

Thank you
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: SQL Database Size check not working

Post by mcapra »

In your command executed from the Nagios Core server:

Code: Select all

root@tgcs017:/usr/local/nagios/etc/objects/windowsservers# /usr/lib/nagios/plugins/check_nrpe -t 50 -H TGCS016 -c check_sqldbsize -a tgcs016\wsussql SUSDB 8000 5000
Have you taken Bash reserved characters into account? You may need a double backslash in your domain account like so when passing it to check_nrpe:

Code: Select all

root@tgcs017:/usr/local/nagios/etc/objects/windowsservers# /usr/lib/nagios/plugins/check_nrpe -t 50 -H TGCS016 -c check_sqldbsize -a tgcs016\\wsussql SUSDB 8000 5000
Former Nagios employee
https://www.mcapra.com/
kwhogster
Posts: 644
Joined: Wed Oct 14, 2015 6:51 pm
Location: Wood Ridge NJ USA
Contact:

Re: SQL Database Size check not working

Post by kwhogster »

# /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.

tgcs016 is the server host name
wsussql is the sql instance
SUSDB is the sql database

Any ideas?
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: SQL Database Size check not working

Post by tgriep »

Try this, encase all of the arguments in between single quotes so they are passed as only one argument.

Code: Select all

/usr/local/nagios/etc/objects/windowsservers# /usr/lib/nagios/plugins/check_nrpe -t 50 -H TGCS016 -c check_sqldbsize -a 'tgcs016\wsussql SUSDB 8000 5000'
The username and password that is used to connect to the Database is hard coded in the VBS script to take a look at it and make sure they are updated for your SQL server account.
Be sure to check out our Knowledgebase for helpful articles and solutions!
kwhogster
Posts: 644
Joined: Wed Oct 14, 2015 6:51 pm
Location: Wood Ridge NJ USA
Contact:

Re: SQL Database Size check not working

Post by kwhogster »

Ok

I found in the vbs script

Source=" & dbserver & ";" & _
"Trusted_Connection=Yes;Initial Catalog=" & dbname & ";" ' & _
' "User ID=sa;Password=password;"

So I changed password to the SA accounts password saved the file and re ran the check Different message but same meaning

:/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.

I checked on the SQL server and SA in not the dbowner and it will not let me make it the dbowner

No matter how I change the script it still runs fine on the server but not from Nagios

Has to be a permissions issue

Thoughts?
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: SQL Database Size check not working

Post by tgriep »

The NSClient++ agent runs as a Local System Account and it may not have sufficient permissions to connect the database. That is why it works on the command line.
Try editing the NSClient++ service on the Windows server and have it use a login account.

Next, your test used a lower case database name but you are using upper case in the command. It should not matter but try using lower case in the command.

Check the MSSQL server log files for any authentication errors.
Be sure to check out our Knowledgebase for helpful articles and solutions!
kwhogster
Posts: 644
Joined: Wed Oct 14, 2015 6:51 pm
Location: Wood Ridge NJ USA
Contact:

Re: SQL Database Size check not working

Post by kwhogster »

Good call

Logon failed for user NT Authority\System for the database.

So I added NT Authority\System to the database and now the command works


Now off to my other SQL server to test will post results

Thank you,
kwhogster
Posts: 644
Joined: Wed Oct 14, 2015 6:51 pm
Location: Wood Ridge NJ USA
Contact:

Re: SQL Database Size check not working

Post by kwhogster »

On my other Server

:/usr/local/nagios/etc/objects# /usr/lib/nagios/plugins/check_nrpe -t 50 -H TGCS014-N1 -c check_sqldbsize -a 'TGCS014-N1-SQLw\wrestling wrestlinghistory 8000 5000'
C:\Program Files\NSClient++\scripts\check_sqldbsize.vbs(33, 1) Microsoft OLE DB Provider for SQL Server: Login failed for user 'OUR\TGCS014-N1$'.



This time it shows a user account
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: SQL Database Size check not working

Post by tgriep »

Glad that the other server is working.
On the new server, did you edit the script and change the username and password to a valid account?
Any special characters in the password? Sometimes they cause issues unless they are escaped.
Be sure to check out our Knowledgebase for helpful articles and solutions!
kwhogster
Posts: 644
Joined: Wed Oct 14, 2015 6:51 pm
Location: Wood Ridge NJ USA
Contact:

Re: SQL Database Size check not working

Post by kwhogster »

Yes me too

Yes the sa account has same password as on my other sql server.

Only letters and numbers in password.

Login failed for user 'OUR\TGCS014-N1$'. this is the problem but not sure why it is trying to logon using this
Locked