Page 2 of 2

Re: Nagios Plugin check_mssql_database.py

Posted: Tue Apr 28, 2015 11:40 am
by lmiltchev
This will require some work. There is nothing available "out of the box". You can probably run and save the following query on the mssql server:

Code: Select all

with fs
as
(
    select database_id, type, size * 8.0 / 1000 size
    from sys.master_files
)
select 
    name,
    (select sum(size) from fs where type = 0 and fs.database_id = db.database_id) DataFileSizeMB,
    (select sum(size) from fs where type = 1 and fs.database_id = db.database_id) LogFileSizeMB
from sys.databases db
You can then run from the CMD something like this (if you saved you query as "DBSizes.sql on the C: drive):

Code: Select all

sqlcmd -S localhost -i C:\DBSizes.sql
You can output it to a text file:

Code: Select all

sqlcmd -S localhost -i C:\DBSizes.sql -o C:\ScriptResults.txt
You can also use "find" to filter the results in order to show the info about one database:

Code: Select all

sqlcmd -S localhost -i C:\DBSizes.sql | find "database name"
Once you make sure your command works in the CMD, you can create a batch script that would run the command and parse the text file, and call the script from Nagios via NCPA or NSClient++.

Re: Nagios Plugin check_mssql_database.py

Posted: Wed Apr 29, 2015 3:53 am
by warnox
I'm surprised there is nothing out of the box, surely other people must be doing this with Nagios.

Would it be possible to do it with a VB script? I'm currently using a VB script to query a SQL database and monitor Backup Exec job failures (http://exchange.nagios.org/directory/Pl ... ec/details). I'm thinking this will potentially involve less steps?

Re: Nagios Plugin check_mssql_database.py

Posted: Wed Apr 29, 2015 10:44 am
by lmiltchev
If you have a script in place already that does the job for you, it would be easier. Again, you can use it with NCPA or NSClient++.

Re: Nagios Plugin check_mssql_database.py

Posted: Wed Apr 29, 2015 3:14 pm
by warnox
I don't have one but I'll write something and post the solution if it works. Never like relying on my programming skills :)

Re: Nagios Plugin check_mssql_database.py

Posted: Wed Apr 29, 2015 5:01 pm
by ssax
That would be great, thanks!

Re: Nagios Plugin check_mssql_database.py

Posted: Tue May 05, 2015 3:03 am
by warnox
Here it is, I think it does the job :)

http://exchange.nagios.org/directory/Pl ... 29/details

Re: Nagios Plugin check_mssql_database.py

Posted: Tue May 05, 2015 9:32 am
by tgriep
Thanks for posting the link. I am sure other people will find this helpful. Thanks a lot!