Archive for 2012

Monitoring Windows with NSClient++

I’ve been playing with Nagios recently and have been using NSClient++ to monitor Windows machines. In some places the documentation wasn’t too great so I thought I’d outline some service checks I’ve got working here. The service definitions here would normally be defined on the Nagios host not on the Windows box itself. Check Windows [...]

Nagios timeperiod for Bank Holidays

The Nagios configuration files come with a timeperiod example for US Public holidays but not for good old Blighty! Obviously that won’t do so here’s one for England & Wales (sorry Scotland!). define timeperiod { name england-wales-holidays timeperiod_name england-wales-holidays alias England & Wales Holidays january 1 00:00-00:00 ; New Years Day march 29 00:00-00:00 ; [...]

MySQL Group By

Many people are caught out by MySQL’s implementation of GROUP BY. By default MySQL does not require that you GROUP BY all non-aggregated columns. For example the following is an illegal query in SQL Server (as well as rather nonsensical); ?View Code MYSQLSELECT * FROM INFORMATION_SCHEMA.TABLES GROUP BY TABLE_SCHEMA; This will generate the following error; [...]

pmp-check-mysql-deleted-files plugin issue

I’ve been busy setting up the Percona Nagios MySQL Plugins  but ran into an issue with the pmp-check-mysql-deleted-files plugin; UNK could not list MySQL’s open files After a little debugging we tracked this down to a problem caused by running multiple instances of mysqld. This is something the script author (Baron Schwartz) mentions in his [...]

Quick Linux Tip: rpm query & xclip

I’m working on a script to do some basic auditing of my Linux servers. One thing I want to record is the install details from an rpm query. The following command will provide us with some basic details of the rpms installed and ordered by date. ?View Code BASHrpm -qa –queryformat ‘%{NAME} %{VERSION} %{INSTALLTIME:date}\n’ –last; [...]

Check the SQL Server Service Account Can Write the SPN

I don’t have access, like many DBAs, to the inner bowels of Active Directory.  While I’m more than happy for it to stay this way I still want to check that certain things have been setup correctly and haven’t been “cleaned-up” by a security nazi focused domain administrator. One such situation arose recently with Service Principal Names. SPNs [...]

MySQL Database Maintenance Stored Procedure

Here’s a very simple stored procedure I use to run some maintenance on MySQL tables. It allows you to run OPTIMIZE TABLE or ANALYZE TABLE on all (or most) tables in a MySQL database. ?View Code MYSQLDELIMITER $$   DROP PROCEDURE IF EXISTS `db_maintenance`$$   CREATE DEFINER = ‘root’@'%’ PROCEDURE db_maintenance ( IN p_mode TINYINT, [...]

Purging data & Partitioning for Paupers

Several months ago at work we started having some terrible problems with some jobs that purge old data from our system. These jobs were put into place before my time, and while fine at the time, were now causing us some big problems. Purging data would take hours and cause horrendous blocking while they were [...]

Check Mirroring Status with Powershell

Here’s a simple Powershell snippet to check the mirroring status on your SQL Server instances. ?View Code POWERSHELL# Load SMO extension [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null;   # Servers to check $sqlservers = @("server1", "server2", "server3"); foreach($server in $sqlservers) { $srv = New-Object "Microsoft.SqlServer.Management.Smo.Server" $server; # Get mirrored databases $databases = $srv.Databases | Where-Object {$_.IsMirroringEnabled -eq $true}; Write-Host [...]

Get-ServerErrors Powershell Function

Here’s a little Powershell function I’m using to check the Event Logs and SQL Server Error Logs in one easy swoop; ?View Code POWERSHELLfunction Get-ServerErrors { # Server to check & hours back. Will only support default sql instances # Could add a third param for instance and modify script where appropriate if needed param ($server, [...]