Wednesday 18 November 2009

New Agent Maintenance Mode

Here is a new version of the Agent Maintenance Mode MP. This version is only for OpsMgr R2 as it leverages the new powershell modules only available in R2.

--Update--
Read this post if this is not working for you -Permissions Required for Agent Maintenance Mode
The readme has also been updated with this info
----

To recap on this solution:
It allows you to start Maintenance Mode from an monitored server using just a vbscript. Using this requires absolutely no permissions in Operations Manager. All of the components required to have this function are part of a standard OS with an agent installed. It works through Gateways so can be used in firewalled or untrusted environments.

The MaintMode.vbs writes an event to the event log that indicates the length of time Maintenance Mode should remain on. This is picked up by the management pack and processed on the RMS to turn on Maintenance Mode for that server. The on time can be specified in days, hours or minutes.

Download here

The zip file contains a Readme with more information and usage instructions.

Highligh of changes in this version:
Management Pack Changes
* Added Powershell modules in MP (R2 feature) to replace scripts on RMS. Some logic reworking in scripts
* Support for Server 2008
* Fixed ON/Off logic to not put Health Service and Health Service Watcher in to Maint Mode as R2 puts HS and HSW in to MM automatically
• Added Maint Mode event collection rules
• Added Schedule Maint Mode text file option at C:\MaintenanceModeSchedule.txt - origional by Steve Rachui - http://blogs.msdn.com/steverac/archive/2008/12/09/maintenance-mode-by-config-file.aspx
* Disables discovery on RMS as Maintenance Mode should not be used on RMS

MaintMode.vbs
* Now logs the username in the event log of who turned it on: “Maintenance Mode: ON for 6 hour(s): 360 . Turned on by domain\user”
* Adds registry markers to indcate current status under HKLM/Software/OpsMgr/Maintenance Mode. Can be used by patching tools.
* Added STATUS option that reads current status from registry.

5 comments:

Shay Byrne said...

Nice one my son :)

Matthew Rogers said...

I look forward to testing this version in the lab tommorow, this is excellent. We have been using your old version (with Steve Rachui's modification) acroos our enterprise.

Pieter Bovy said...

I wonder if you could provide some clarification for me? I've imported and tested the solution, but it doesn't seem to work. It creates the eventlog message, but the RMS doesn't pick it up. I've checked permissions -> RMS ActionAccount = SCOM admin. If I check the contents of the MP, I seem to be missing a monitor to check the eventid. Is a monitor needed for this solution?

Derek Harkin said...

It is a rule that detects the event ID.

First check that discovery has compelted. By default discovery runs only every 4 hours.
You can cehck this using the "Discovered Inventory" view in the console and changing the target to the Agent maintenance mode class.

To test if your RMS is configured correctly run the below powershell script on your RMS.
You need to modify the first line with the computer name of the server you wnat ot put in Maint Mode. If it is a Windows 2003 or below you need to use just the Netbios name. If it is Server 2008 then you need to use the FQDN.




$ComputerName = (name of computer to put in to MM)

$rootMS="localhost"
add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";
set-location "OperationsManagerMonitoring::";
new-managementGroupConnection -ConnectionString:$rootMS;

$length = 30

$startTime = [System.DateTime]::Now
$endtime = [System.DateTime]::Now
$endtime = $endtime.AddMinutes($length)

$computerClass = get-monitoringclass -name:Microsoft.Windows.Computer

$computerName = $computerName.ToUpper()
if($computername -match "\.")
{$computerCriteria = "PrincipalName = '" + $computerName + "'"}
else
{$computerCriteria = "NetbiosComputerName = '" + $computerName + "'"}

$computer = get-monitoringobject -monitoringclass:$computerClass -criteria:$computerCriteria

New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$computer -comment:"Test"

$MaintModeClass = get-monitoringclass -name:AgentMaintMode_Class
$MaintModes = $computer.GetRelatedMonitoringObjects($MaintModeClass)
$MaintMode = $MaintModes[0]
$MaintMode.StopMaintenanceMode([System.DateTime]::Now.ToUniversalTime(),[Microsoft.EnterpriseManagement.Common.TraversalDepth]::Recursive);

J. Greg Mackinnon said...

Thanks for this excellent work, Derek.

I have used your management pack to enable automatic entering of maintenance mode of all of our systems after Windows Update triggers a system reboot. This is something that I have long wanted to do, but previously was not able to accomplish.

To make the solution work, I had to add some additional scripts and Group Policy settings... I have detailed my work here:
http://www.uvm.edu/~jgm/wordpress/?p=229