Re: Nagios Plugin check_mssql_database.py
Posted: Tue Apr 28, 2015 11:40 am
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:
You can then run from the CMD something like this (if you saved you query as "DBSizes.sql on the C: drive):
You can output it to a text file:
You can also use "find" to filter the results in order to show the info about one database:
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++.
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 dbCode: Select all
sqlcmd -S localhost -i C:\DBSizes.sqlCode: Select all
sqlcmd -S localhost -i C:\DBSizes.sql -o C:\ScriptResults.txtCode: Select all
sqlcmd -S localhost -i C:\DBSizes.sql | find "database name"