Attention! New version of this MP is available. See blog: https://systemcentertipps.wordpress.com/2013/01/07/updated-mp-sample-agent-maintenance-mode-mp-version-1-0-0-2/
Every Operations Manager administrator will hit the maintenance mode problem some times. It is not always useful to only have the option setting the maintenance mode through the console or with the minimum of Operator role permissions – as it is defined in OpsManager.
So with 2007 we implemented a agent based maintenance mode solution (provided by our Microsoft consultant Jens Morawietz – thanks for that!). So every user, which logs on to a server will see a splash screen which enables the user to set the maintenance mode directly on the machine without the need of the console and without permissions in Operations Manager. One additional request was: being able to set the maintenance mode through script for using in scheduled tasks. One example is a regular offline backup which brings a service down and where no alerts should be created. So the solution also offers a Visual Basic script, that can be added to those tasks.
With the upgrade to Operations Manager 2012 we had to change the solution a bit (use SCOM 2012 cmdlets, changed to PowerShell, etc.). So I post the 2012 solution here.
1. The maintenance mode splash screen (or the TriggerOM12MM.Instance.Event.vbs script) writes an event into the OperationsManager event log
2. A rule on the agent checks if this event occurs and creates an informational alert. (part of Sample.Agent.MaintenanceMode.MP)
3. A second rule on the agent checks if this event occurs and triggers a PowerShell write action on the assigned management server to start the maintenance mode. (part of Sample.Agent.MaintenanceMode.MP)
1 a. The maintenance mode splash screen
The script behind this splash screen is written in PowerShell. So each agent, which should use this functionality needs PowerShell 2.0 and the OpsManager shell installed (links!).
The user sets the duration, reason and a enters a comment. Then the user can decide if only maintenance mode should be set or also a shutdown or reboot of the machine should be initiated. If a shutdown or reboot should be started, then the script waits 60 seconds to give the workflow time setting the maintenance mode first.
As soon as the user hits enter (that initializes maintenance mode only) or one of the buttons, an informational event is written to the Operations Manager event log.
This window indicates, that the log entry was created:
Then the script waits up to 5 minutes and checks if there are new events with the id 1215 in the OpsManager event log which indicate that the agent started maintenance mode.
The script will show this window, if the server is set into maintenance successfully:
Or it will show this window, if the maintenance mode was not started within the 5 minutes wait time:
You need to distribute this splash screen separately to the management pack to all agents, that should use this functionality. We have used SCCM for that. You will find a folder called MM in the Zip file which is linked to my post on System Center Central (see bottom). Copy this to the agents C:\ drive and copy the contained OpsMgrmm Shortcut to the Desktop of all users or to the Startup folder in the Start Menu of all users.
I also recommend to change add your company logo to the folder and call it “logo.gif” and enter a correct email address to contact the Operations Manager administrators in the OpsMgrMM.ps1 line 264:
$objContact.Text =“Please contact firstname.lastname@example.org for assistance.”
The shortcut starts the PowerShell script in a hidden shell with the execution policy “Remotesigned”. So you do not need to change the default execution policy.
1 b. The TriggerOM12MM.Instance.Event.vbs script
The script is also located in the C:\MM folder. It also writes the same event log entry as the Maintenance mode splash screen. The difference is, that you can also specify a class and an instance to be set into maintenance mode.
cscript TriggerOM12MM.INstance.Event.vbs <maintenance mode duration in mins> <comment for maintenance> <class> <instance>
cscript.exe TriggerOM12MM.Instance.Event.vbs 15 “Monthly server reboot.” “Microsoft.Windows.Server.2003.LogicalDisk” “C:”
If you want to set the a complete class with all instances into maintenance, then change it like this:
cscript.exe TriggerOM12MM.Instance.Event.vbs 15 “Monthly server reboot.” “Microsoft.Windows.Server.2003.LogicalDisk” “”
If you want to set the whole server into maintenance, then change it like this:
cscript.exe TriggerOM12MM.Instance.Event.vbs 15 “Monthly server reboot.” “” “”
The script waits 3 min and then ends. So the server has time to go through the workflow and set the maintenance mode.
If you have a regular task, that stops a resource then add the call of this script at the beginning of your command line and then go on with your steps.
Now we have to move to the Sample.Agent.MaintenanceMode.MP
Import this Mp into your Operations Manager 2012 environment. The management pack will create two rules and a Run as Profile.
Sample – Event Log Entry Triggers Alert Rule
Sample – Event Log Entry triggers Maintenance Mode Rule
=> Both rules are targetted to “Microsoft.Windows.OperatingSystem”, so they will run on all Windows computers.
Run as Profile:
Sample Operations Manager Administrator Run As Profile
=> Assign a Operations Manager administrator user to this profile!
2. Sample – Event Log Entry Triggers Alert Rule
This rule checks for the event 997 in the Operations Manager event log on the agent and creates an informational alert.
Name: Sample Maintenance Mode 2012 – Maintenance Mode was Triggered On The Agent
Source: Microsoft Windows Server 2008 R2 Standard
Full Path Name: Servername\Microsoft Windows Server 2008 R2 Standard
Alert Rule: Sample – Event Log Entry Triggers Alert Rule
Created: 8/2/2012 5:52:55 AM
The maintenance mode was triggered on: Microsoft Windows Server 2008 R2 Standard . Event Description: TriggerOM12MM.Instance.vbs 1.1 : Start;15;PlannedOther;;;Test:domain\username;8/2/2012 5:52:55 AM.
3. Sample – Event Log Entry triggers Maintenance Mode Rule
This rule checks for the event 997 in the Operations Manager event log on the agent and starts a write action on the asigned management server.
<WriteAction ID=”WA” TypeID=”Sample.Agent.MaintenanceMode.EventlogEntryTriggersMM.WriteAction” Target=”SC!Microsoft.SystemCenter.ManagementServer”>
This write action is based on a PowerShell 2.0 script, so the management server also needs PowerShell 2.0 installed.
The write action itself uses the defined run as profile (Sample Operations Manager Administrator Run As Profile), where a user with Operations Manager administrator permissions needs to be assigned to. Otherwise the write action will not work!
<WriteActionModuleType ID=”Sample.Agent.MaintenanceMode.EventlogEntryTriggersMM.WriteAction” Accessibility=”Internal” RunAs=”Sample.Agent.MaintenanceMode.OpsMgrAdmin.RunAsProfile” Batching=”false”>
The write action will set the maintenance mode depending on how the event description looks like.
TriggerOM12MM.Instance.vbs 1.1 : Start;15;PlannedOther;;;Test:domain\username;8/2/2012 5:52:55 AM
<Will be ignored>;<Duration>;<Class>;<Instance>;<Comment>;<Will be ignored>
Here you can download the Zip file: http://www.systemcentercentral.com/PackCatalog/PackCatalogDetails/tabid/145/IndexId/94882/Default.aspx