How to monitor sql server switch to mirror database

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Frédéric GRANAT
Posts: 445
Joined: Mon Nov 19, 2012 11:36 am

How to monitor sql server switch to mirror database

Post by Frédéric GRANAT »

Hi,
We've got two databases in mirroring (a main database and a mirror database).
We need to monitor when there's a switch to the mirror database.

How could I do that ?

Frederic
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: How to monitor sql server switch to mirror database

Post by abrist »

Are these dbs mysql, or mssql, or something else?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Frédéric GRANAT
Posts: 445
Joined: Mon Nov 19, 2012 11:36 am

Re: How to monitor sql server switch to mirror database

Post by Frédéric GRANAT »

Hi,
Microsoft SQL Server please
belvdr
Posts: 81
Joined: Tue Oct 08, 2013 9:17 pm

Re: How to monitor sql server switch to mirror database

Post by belvdr »

I would suggest writing a SQL Server query monitor. Query sys.database_mirroring (http://technet.microsoft.com/en-us/libr ... 78655.aspx) to determine each server's state.

Code: Select all

SELECT mirroring_role FROM sys.database_mirroring
The principal should return 1 and the mirror(s) should return 2.

Alternatively, configure SQL Server to send out alerts directly: http://technet.microsoft.com/en-us/libr ... 66392.aspx

EDIT: It looks like my last edit was removed. You can modify the query above to query individual databases:

Code: Select all

SELECT mirroring_role FROM sys.database_mirroring WHERE database_id = DB_ID('<database name>');
Last edited by belvdr on Mon May 05, 2014 12:57 pm, edited 2 times in total.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: How to monitor sql server switch to mirror database

Post by lmiltchev »

Frédéric GRANAT, let us know if belvdr's suggestion helped you solve your issues.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Frédéric GRANAT
Posts: 445
Joined: Mon Nov 19, 2012 11:36 am

Re: How to monitor sql server switch to mirror database

Post by Frédéric GRANAT »

Hi,
I would like to run check_mssql using "Windows authentication" and not "SQL Server Authentication" please tell me how to proceed.

Regards,

Frederic
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: How to monitor sql server switch to mirror database

Post by lmiltchev »

You are not going to be able to use "Windows authentication" with this plugin. The issue has been discussed in the past on the forum:

https://support.nagios.com/forum/viewto ... 0&start=10

I am not sure if there is another plugin the Nagios Exchange that can offer you this functionality. I haven't seen one, yet.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Frédéric GRANAT
Posts: 445
Joined: Mon Nov 19, 2012 11:36 am

Re: How to monitor sql server switch to mirror database

Post by Frédéric GRANAT »

Hi,
I created an "sa" account.
The check works correctly but the "Test Check Command" in Nagiosxi doesn't work :
COMMAND: /usr/local/nagios/libexec/check_mssql -H xxxxxxxxxx -U sa -P xxxxxxxxxx -d xxxxxxxx -q "SELECT mirroring_role FROM sys.database_mirroring WHERE database_id = DB_ID\(\'xxxxx\'\)" -r 1
OUTPUT: CRITICAL: Could not execute the query.

Here's $arg1$ : -H xxxxxxxxxx -U sa -P xxxxxxxxxx -d xxxxxxxx -q "SELECT mirroring_role FROM sys.database_mirroring WHERE database_id = DB_ID('xxxxx')" -r 1

If I run the $arg1$ via ssh running : /usr/local/nagios/libexec/check_mssql -H xxxxxxxxxx -U sa -P xxxxxxxxxx -d xxxxxxxx -q "SELECT mirroring_role FROM sys.database_mirroring WHERE database_id = DB_ID('xxxxx'), it works.

We can conclude that, when clicking on "Test Check Command", Nagiosxi add serveral "\", that makes the query fail.

How can I solve that problem ?

Rgds,

Frederic
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: How to monitor sql server switch to mirror database

Post by hsmith »

The test check command button has a lot of issues with the way that it handles special characters. If you're going to run a test, the true way to test it is by running it from the command line. We're hoping to see improved functionality on the test button in the future, but it's not reliable at the moment.
Former Nagios Employee.
me.
Frédéric GRANAT
Posts: 445
Joined: Mon Nov 19, 2012 11:36 am

Re: How to monitor sql server switch to mirror database

Post by Frédéric GRANAT »

Hi,
Thanks, you can close the post.

Frederic
Locked