Tuesday 19 February 2008

Initiate Maintenance Mode from an Agent (no extras installed)

---Update---

Updated version of this MP at http://derekhar.blogspot.com/2009/11/new-agent-maintenance-mode.html


---------


This post will detail a method to initiate Maintenance Mode from an agent managed computer using a vbscript. This method is useful in the case where the people doing patching are not the same people who use the Operations Console and when you cannot dictate what is to be installed in the server. Clive Eastwood's AgentMM for example, if run remotely requires .NET 3.0, Operations Manager specific dll's, Admin permissions on OpsMgr and the ability to connect to the SDK service on the RMS.

Using this method, the person running the command needs to have absolutely no permissions on Ops Manager. All of the components required to have this function are part of a standard OS with and agent installed. It works through Gateways so can be used in firewalled or untrusted environments if you have a gateway in place.

There are 3 parts to this solution:

1) A VBScript on each managed computer that writes an event to the local event log.

2) A Management pack containing an rule that detects this event and runs a response on the RMS.

3) The response executes a Powershell script on the RMS that puts the server in to Maintenance Mode. I have borrowed pieces of the powershell script from Boris.


VBScript

Powershell Script

Management Pack

The vbscript is pretty simple and just writes an event to the event log that indicates the length of time Maintenance Mode should remain on. This time is passed as a parameter to the script.

Usage: MaintModeOn 4

- This command turns on Maintenance Mode for 4 hours

The single rule in the management pack picks up the event from the Application Log with event ID of 0, with a source of WSH and where the description contains the words "Maintenance Mode". In response, the rule runs the Powershell script MaintModeON.ps1 and passes to it two parameters -the name of the computer where the script was run and the event description.

The Powershell script puts all three pieces of an agent in the Maintenance Mode. This Powershell script should be copied to the System Center Operations Manager 2007 program folder on the root management server. If you have clustered the RMS it should be in the folder on both nodes.



---Update---

I have updated the links since google appears to have taken down the site hosting the files.

9 comments:

Raphael Burri said...

Hi Derek

Thanks for posting this. Works great for me.

I have simplified this a bit by including the Powershell script directly into the management pack. That way I do not have to worry about placing the .ps1 file into the right directory.


<CommandLine>"&amp; '$file/MaintMode.On.ps1$' '$Data/LoggingComputer$' '$Data/EventDescription$'"</CommandLine>

<TimeoutSeconds>300</TimeoutSeconds>

<RequireOutput>true</RequireOutput>

<Files>

<File>

<Name>MaintMode.On.ps1</Name>

<Contents><![CDATA[

param($computerName, $EventDescription).............

]]>

</Contents>

</File>

</Files>



Raphael

Anonymous said...

Thank you for this cool tool. I tried it exactly how you said it but not having any luck. May be i haven't waited long enough. I ran the command from the agent and created a file on the event viewer with event id "0" but when I look at the console i don't see those agents on the maintenance mode. Please let me know. Thanks.

Romano Jerez said...

Is it possible to take the host out of maintenance mode the same way (via a script executed locally on the monitored machine)?

Derek Harkin said...

It is possible to do on and off and I am putting together the post right now with a new MP and scripts

Robert.g said...

I am monitoring UPS SNMP device and when the device is in error it must run a recovery script which of cause cannot run on the SNMP device. Can you get the script to run on the Proxy agent or the RMS. The script shuts down all servers connected to the UPS

Anonymous said...

Derek, nice work. I modified the MP to allow administrators to create config files on their systems to note when maintenance mode should occur - I introduced a script to read the file post an event when the time comes to enter maintenance mode. I've posted the modified version to my blog at http://blogs.msdn.com/steverac/archive/2008/12/09/maintenance-mode-by-config-file.aspx

Steve

Anonymous said...

Derek, nice work. I've introduced a modification that allows administrators to configure a flat file on their systems to specify when maintenance mode should trigger and how long it lasts. This file is read by script and the event triggered to initiate maintenance mode. I've placed the event in the OpsMgr event log. You can access the modified MP at http://blogs.msdn.com/steverac/archive/2008/12/09/maintenance-mode-by-config-file.aspx

Javier said...

Hi

Unfortunately, did does not work for me.

In fact, nothing happens at all (I am looking at the "Windows Computers" state view in the console and the server where I run this never changes its state to Maintenance Mode.

I cannot see any errors, or anything in the OpsMgr event log, the Powershell event log, etc

I am using opsmgr R2

It would be very nice to get some help as I am in need of this solution really

Thanks

Anonymous said...

Javier, the PowerShell script needs to be modified to work with R2. Comment out (#) the commands that put the health service and watcher into MM.

# New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$healthService -comment:$comment
# New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$healthServiceWatcher -comment:$comment