SQL Database Size check not working

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

SQL Database Size check not working

Postby kwhogster » Tue Nov 06, 2018 11:09 pm

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
kwhogster
 
Posts: 532
Joined: Wed Oct 14, 2015 6:51 pm
Location: Wood Ridge NJ USA

Re: SQL Database Size check not working

Postby mcapra » Wed Nov 07, 2018 9:48 am

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
http://www.mcapra.com/
User avatar
mcapra
 
Posts: 3441
Joined: Thu May 05, 2016 3:54 pm

Re: SQL Database Size check not working

Postby kwhogster » Wed Nov 07, 2018 10:17 am

# /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?
kwhogster
 
Posts: 532
Joined: Wed Oct 14, 2015 6:51 pm
Location: Wood Ridge NJ USA

Re: SQL Database Size check not working

Postby tgriep » Wed Nov 07, 2018 3:21 pm

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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
tgriep
Madmin
 
Posts: 7237
Joined: Thu Oct 30, 2014 9:02 am

Re: SQL Database Size check not working

Postby kwhogster » Wed Nov 07, 2018 7:50 pm

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?
kwhogster
 
Posts: 532
Joined: Wed Oct 14, 2015 6:51 pm
Location: Wood Ridge NJ USA

Re: SQL Database Size check not working

Postby tgriep » Thu Nov 08, 2018 10:55 am

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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
tgriep
Madmin
 
Posts: 7237
Joined: Thu Oct 30, 2014 9:02 am

Re: SQL Database Size check not working

Postby kwhogster » Thu Nov 08, 2018 1:35 pm

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: 532
Joined: Wed Oct 14, 2015 6:51 pm
Location: Wood Ridge NJ USA

Re: SQL Database Size check not working

Postby kwhogster » Thu Nov 08, 2018 1:55 pm

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
kwhogster
 
Posts: 532
Joined: Wed Oct 14, 2015 6:51 pm
Location: Wood Ridge NJ USA

Re: SQL Database Size check not working

Postby tgriep » Thu Nov 08, 2018 3:07 pm

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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
tgriep
Madmin
 
Posts: 7237
Joined: Thu Oct 30, 2014 9:02 am

Re: SQL Database Size check not working

Postby kwhogster » Thu Nov 08, 2018 3:20 pm

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
kwhogster
 
Posts: 532
Joined: Wed Oct 14, 2015 6:51 pm
Location: Wood Ridge NJ USA

Next

Return to Nagios Core

Who is online

Users browsing this forum: No registered users and 11 guests