Integrating VMM and OpsMgr Maintenance Mode

Integrating VMM and OpsMgr Maintenance Mode

  • Comments 6
  • Likes

As part of VMM 2008 R2 we have added a new feature called maintenance mode.  This feature enables users to easily evacuate the VMs from a host in order to perform host maintenance (for more information on VMM's maintenance mode check out Cheng's blog post here).  Since the introduction of this feature we have gotten several questions/comments about integrating this new VMM feature with maintenance mode in System Center Operations Manager.   Well check out the attached MP.  This MP will monitor the VMM server and track when hosts are put into maintenance mode and then call into Operations Manager and put the respective host object into maintenance mode and vice versa, watch for hosts being removed from maintenance mode in VMM and then taking the respective host object in OpsMgr out of maintenance mode. 

For those of you familiar with management packs, you can see with a pretty simple and straight forward MP you can easily tie together the states of your hosts.  While the MP has not been extensively tested it should give you a good idea on how to accomplish the task at hand.

Hope you find this helpful

 

Alan Goodman

Senior Program Manager

System Center Virtual Machine Manager

 

 

Installation Note:  This management pack is intended for use with Operations Manager 2007 or Operations Manager 2007 R2 with Virtual Machine Manager 2008 R2, and requires at least the beta version or later or the VMM 2008 R2 management pack.  Copy the text in the box below into a text file and save it as MaintenanceModeSample.xml and import it into OpsMgr.

Management Pack: 

<ManagementPack ContentReadable="true" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <Manifest>

    <Identity>

      <ID>MaintenanceModeSample</ID>

      <Version>1.0.0.18</Version>

    </Identity>

    <Name>MaintenanceMode.Sample</Name>

    <References>

      <Reference Alias="SCDW">

        <ID>Microsoft.SystemCenter.DataWarehouse.Library</ID>

        <Version>6.1.7043.0</Version>

        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>

      </Reference>

      <Reference Alias="SystemCenter">

        <ID>Microsoft.SystemCenter.Library</ID>

        <Version>6.1.7043.0</Version>

        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>

      </Reference>

      <Reference Alias="VMM">

        <ID>Microsoft.SystemCenter.VirtualMachineManager.2008.R2</ID>

        <Version>2.0.4056.0</Version>

        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>

      </Reference>

      <Reference Alias="WL">

        <ID>Microsoft.Windows.Library</ID>

        <Version>6.1.7043.0</Version>

        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>

      </Reference>

      <Reference Alias="SL">

        <ID>System.Library</ID>

        <Version>6.1.7043.0</Version>

        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>

      </Reference>

    </References>

  </Manifest>

  <TypeDefinitions>

    <ModuleTypes>

      <!-- Start maintenance mode write action for PowerShell script -->

      <WriteActionModuleType ID="MaintenanceMode.StartAction" Accessibility="Internal" Batching="false">

        <Configuration>

          <xsd:element minOccurs="1" name="TaskId" type="xsd:string" />

        </Configuration>

        <OverrideableParameters>

          <OverrideableParameter ID="EventData" Selector="$Config/TaskId$" ParameterType="string" />

        </OverrideableParameters>

        <ModuleImplementation Isolation="Any">

          <Composite>

            <MemberModules>

              <WriteAction ID="StartAction" TypeID="SL!System.CommandExecuter">

                <ApplicationName>

                  <![CDATA[%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe]]>

                </ApplicationName>

                <WorkingDirectory />

                  <CommandLine><![CDATA["& '$file/StartMMScript.ps1$' '$Config/TaskId$'"]]></CommandLine>

                <TimeoutSeconds>120</TimeoutSeconds>

                <RequireOutput>false</RequireOutput>

                <Files>

                  <File>

                    <Name>StartMMScript.ps1</Name>

                    <Contents>

                      <![CDATA[

                      Param($TaskId);

                                           

                      #Add the VMM and OM Snapins

                      Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager

                      Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client

                     

                      #connect to the VMM server

                      $VMMS = Get-VMMServer localhost

                      if( $Error.Count -ne 0)

                      {

                         eventcreate /T Error /ID 101 /L APPLICATION /SO VMM-MP /D "Failed to put host into maintenance mode: " + $Error[0]

                         return;

                      }

                                           

                      #Get the OpsMgr Server Name

                      $MSName = $VMMS.OpsMgrServer

                     

                      #establish console session with OM

                      & 'C:\Program Files\System Center Operations Manager 2007\Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Functions.ps1'

                      Start-OperationsManagerClientShell -ManagementServerName: $MSName -PersistConnection: $true -Interactive: $false;

                      if( $Error.Count -ne 0)

                      {

                         eventcreate /T Error /ID 101 /L APPLICATION /SO VMM-MP /D "Failed to put host into maintenance mode: " + $Error[0]

                         return;

                      }

                     

                      #Get the VMM Job that put the host into maintenance mode

                      $TriggerJob = Get-Job -Id $TaskId

 

                      #Get the VMM Host Object

                      $MMHost = Get-VMHost -Id  $TriggerJob.TargetObjectID

                     

                      #Get the OM computer object

                      $ComputerClass = Get-MonitoringClass -Name 'System.Computer'

                      $ComputerObject = Get-MonitoringObject -MonitoringClass $ComputerClass -Path "\" | Where {$_.PathName -eq $MMHost.Name}

 

                      #Put the OM computer into Maintenance Mode

                      $time = [DateTime]::Now

                      New-MaintenanceWindow -MonitoringObject $ComputerObject -Comment "Putting into maintenance mode because VMM is in Maintenance Mode" -StartTime $time -EndTime $time.AddYears(99)

                     

                      eventcreate /T Information /ID 100 /L APPLICATION /SO VMM-MP /D 'Host computer is now in maintenance mode'

                      ]]>

                    </Contents>

                  </File>

                </Files>

              </WriteAction>

            </MemberModules>

            <Composition>

              <Node ID="StartAction" />

            </Composition>

          </Composite>

        </ModuleImplementation>

        <OutputType>SL!System.CommandOutput</OutputType>

        <InputType>SL!System.BaseData</InputType>

      </WriteActionModuleType>

      <!-- Stop maintenance mode write action for PowerShell script -->

      <WriteActionModuleType ID="MaintenanceMode.StopAction" Accessibility="Internal" Batching="false">

        <Configuration>

          <xsd:element minOccurs="1" name="TaskId" type="xsd:string" />

        </Configuration>

        <OverrideableParameters>

          <OverrideableParameter ID="EventData" Selector="$Config/TaskId$" ParameterType="string" />

        </OverrideableParameters>

        <ModuleImplementation Isolation="Any">

          <Composite>

            <MemberModules>

              <WriteAction ID="StartAction" TypeID="SL!System.CommandExecuter">

                <ApplicationName>

                  <![CDATA[%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe]]>

                </ApplicationName>

                <WorkingDirectory />

                <CommandLine><![CDATA["& '$file/StopMMScript.ps1$' '$Config/TaskId$'"]]></CommandLine>

                <TimeoutSeconds>120</TimeoutSeconds>

                <RequireOutput>false</RequireOutput>

                <Files>

                  <File>

                    <Name>StopMMScript.ps1</Name>

                    <Contents>

                      <![CDATA[

                      Param($TaskId);

                     

                      #Add the VMM and OM Snapins

                      Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager

                      Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client

                     

                      #connect to the VMM server

                      $VMMS = Get-VMMServer localhost

                      if( $Error.Count -ne 0)

                      {

                         eventcreate /T Error /ID 101 /L APPLICATION /SO VMM-MP "Failed to remove host computer from maintenance mode: " + $Error[0]

                      }

                     

                      #Get the OpsMgr Server Name

                      $MSName = $VMMS.OpsMgrServer

 

                      #establish console session with OM

                      & 'C:\Program Files\System Center Operations Manager 2007\Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Functions.ps1'

                      Start-OperationsManagerClientShell -ManagementServerName: $MSName -PersistConnection: $true -Interactive: $false;

                     

                      #Get the VMM Job that put the host into maintenance mode

                      $TriggerJob = Get-Job -Id $TaskId

 

                      #Get the VMM Host Object

                      $MMHost = Get-VMHost -Id  $TriggerJob.TargetObjectID

                     

                      #Get the OM computer object

                      $ComputerClass = Get-MonitoringClass -Name 'System.Computer'

                      $ComputerObject = Get-MonitoringObject -MonitoringClass $ComputerClass -Path "\" | Where {$_.PathName -eq $MMHost.Name}

                     

                      #Remove the OM computer From Maintenance Mode

                      $time = [DateTime]::Now

                      Set-MaintenanceWindow -MonitoringObject $ComputerObject -Comment "Removing from maintenance mode because VMM is out of Maintenance Mode" -EndTime $time

                     

                      eventcreate /T Information /ID 100 /L APPLICATION /SO VMM-MP /D 'Removed Host From Maintenance Mode'

                      ]]>

                    </Contents>

                  </File>

                </Files>

              </WriteAction>

            </MemberModules>

            <Composition>

              <Node ID="StartAction" />

            </Composition>

          </Composite>

        </ModuleImplementation>

        <OutputType>SL!System.CommandOutput</OutputType>

        <InputType>SL!System.BaseData</InputType>

      </WriteActionModuleType>

    </ModuleTypes>

  </TypeDefinitions>

  <Monitoring>

    <Rules>

      <!-- Stop Maintenance Mode Rule-->

      <Rule ID="MaintenanceMode.Sample.StopMM.Rule" Enabled="true" Target="VMM!Microsoft.SystemCenter.VirtualMachineManager.2008.Engine" ConfirmDelivery="true" Remotable="true" Priority="Normal" DiscardLevel="100">

        <Category>Custom</Category>

        <DataSources>

          <DataSource ID="DS" TypeID="WL!Microsoft.Windows.EventCollector">

            <ComputerName>$Target/Host/Property[Type="WL!Microsoft.Windows.Computer"]/NetworkName$</ComputerName>

            <LogName>VM Manager</LogName>

            <AllowProxying>false</AllowProxying>

            <Expression>

              <And>

                <Expression>

                  <SimpleExpression>

                    <ValueExpression>

                      <XPathQuery Type="UnsignedInteger">EventDisplayNumber</XPathQuery>

                    </ValueExpression>

                    <Operator>Equal</Operator>

                    <ValueExpression>

                      <Value Type="UnsignedInteger">1705</Value>

                    </ValueExpression>

                  </SimpleExpression>

                </Expression>

                <Expression>

                  <SimpleExpression>

                    <ValueExpression>

                      <XPathQuery Type="String">PublisherName</XPathQuery>

                    </ValueExpression>

                    <Operator>Equal</Operator>

                    <ValueExpression>

                      <Value Type="String">Virtual Machine Manager</Value>

                    </ValueExpression>

                  </SimpleExpression>

                </Expression>

                <Expression>

                  <SimpleExpression>

                    <ValueExpression>

                      <XPathQuery Type="String">Params/Param[3]</XPathQuery>

                    </ValueExpression>

                    <Operator>Equal</Operator>

                    <ValueExpression>

                      <Value Type="String">Stop maintenance mode</Value>

                    </ValueExpression>

                  </SimpleExpression>

                </Expression>

              </And>

            </Expression>

          </DataSource>

        </DataSources>

        <WriteActions>

          <WriteAction ID="WriteToDB" TypeID="SystemCenter!Microsoft.SystemCenter.CollectEvent" />

          <WriteAction ID="WriteToDW" TypeID="SCDW!Microsoft.SystemCenter.DataWarehouse.PublishEventData" />

          <WriteAction ID="MaintenanceMode.Sample.RunStopMM" TypeID="MaintenanceMode.StopAction">

            <TaskId>$Data/Params/Param[2]$</TaskId>

          </WriteAction>

        </WriteActions>

      </Rule>

      <!-- Start Maintenance Mode Rule-->

      <Rule ID="MaintenanceMode.Sample.StartMM.Rule" Enabled="true" Target="VMM!Microsoft.SystemCenter.VirtualMachineManager.2008.Engine" ConfirmDelivery="true" Remotable="true" Priority="Normal" DiscardLevel="100">

        <Category>Custom</Category>

        <DataSources>

          <DataSource ID="DS" TypeID="WL!Microsoft.Windows.EventCollector">

            <ComputerName>$Target/Host/Property[Type="WL!Microsoft.Windows.Computer"]/NetworkName$</ComputerName>

            <LogName>VM Manager</LogName>

            <AllowProxying>false</AllowProxying>

            <Expression>

              <And>

                <Expression>

                  <SimpleExpression>

                    <ValueExpression>

                      <XPathQuery Type="UnsignedInteger">EventDisplayNumber</XPathQuery>

                    </ValueExpression>

                    <Operator>Equal</Operator>

                    <ValueExpression>

                      <Value Type="UnsignedInteger">1704</Value>

                    </ValueExpression>

                  </SimpleExpression>

                </Expression>

                <Expression>

                  <SimpleExpression>

                    <ValueExpression>

                      <XPathQuery Type="String">PublisherName</XPathQuery>

                    </ValueExpression>

                    <Operator>Equal</Operator>

                    <ValueExpression>

                      <Value Type="String">Virtual Machine Manager</Value>

                    </ValueExpression>

                  </SimpleExpression>

                </Expression>

                <Expression>

                  <SimpleExpression>

                    <ValueExpression>

                      <XPathQuery Type="String">Params/Param[3]</XPathQuery>

                    </ValueExpression>

                    <Operator>Equal</Operator>

                    <ValueExpression>

                      <Value Type="String">Refresh host</Value>

                    </ValueExpression>

                  </SimpleExpression>

                </Expression>

              </And>

            </Expression>

          </DataSource>

        </DataSources>

        <WriteActions>

          <WriteAction ID="WriteToDB" TypeID="SystemCenter!Microsoft.SystemCenter.CollectEvent" />

          <WriteAction ID="WriteToDW" TypeID="SCDW!Microsoft.SystemCenter.DataWarehouse.PublishEventData" />

          <WriteAction ID="MaintenanceMode.Sample.RunStartMM" TypeID="MaintenanceMode.StartAction">

            <TaskId>$Data/Params/Param[2]$</TaskId>

          </WriteAction>

        </WriteActions>

      </Rule>

    </Rules>

  </Monitoring>

  <LanguagePacks>

    <LanguagePack ID="ENU" IsDefault="false">

      <DisplayStrings>

        <DisplayString ElementID="MaintenanceMode.StartAction">

          <Name>Start Host Maintenance Mode Action</Name>

          <Description />

        </DisplayString>

        <DisplayString ElementID="MaintenanceModeSample">

          <Name>Maintenance Mode Sample MP</Name>

        </DisplayString>

        <DisplayString ElementID="MaintenanceMode.Sample.StopMM.Rule">

          <Name>Stop Maintenance Mode Rule</Name>

        </DisplayString>

        <DisplayString ElementID="MaintenanceMode.Sample.StartMM.Rule">

          <Name>Start Maintenance Mode Rule</Name>

        </DisplayString>

      </DisplayStrings>

    </LanguagePack>

  </LanguagePacks>

</ManagementPack>

 

This posting is provided "AS IS" with no warranties, and confers no rights. User assumes all.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • PingBack from http://www.ditii.com/2009/06/09/management-pack-to-integrate-vmm-and-opsmgr-maintenance-mode/

  • Source: System Center Virtual Machine Manager Alan Goodman: “Since the introduction of this feature we

  • This is very good news was well informed that the followers of the issue I am. Thank you ...

  • Introducing such a topic you'd like to congratulate you've let us know. Have good work.

  • This and similar information-sharing my vocabulary expanded again. Thank you for your writing ...

  • Hi Team,

    Is there are new version of this MP that is compliant with SCOM 2007 R2 CU5?