Nagios Plugin check_mssql_database.py

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios Plugin check_mssql_database.py

Post 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++.
Be sure to check out our Knowledgebase for helpful articles and solutions!
warnox
Posts: 39
Joined: Thu Nov 20, 2014 5:22 am

Re: Nagios Plugin check_mssql_database.py

Post 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?
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios Plugin check_mssql_database.py

Post 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++.
Be sure to check out our Knowledgebase for helpful articles and solutions!
warnox
Posts: 39
Joined: Thu Nov 20, 2014 5:22 am

Re: Nagios Plugin check_mssql_database.py

Post 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 :)
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Nagios Plugin check_mssql_database.py

Post by ssax »

That would be great, thanks!
warnox
Posts: 39
Joined: Thu Nov 20, 2014 5:22 am

Re: Nagios Plugin check_mssql_database.py

Post by warnox »

Here it is, I think it does the job :)

http://exchange.nagios.org/directory/Pl ... 29/details
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: Nagios Plugin check_mssql_database.py

Post by tgriep »

Thanks for posting the link. I am sure other people will find this helpful. Thanks a lot!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked