Skip to main content

monitoring group changes with opsmgr

this is relatively simple to do, but i wanted to post it here in case you need to do this yourself.  after you get the alert rule set up, we’ll diverge into using notification channel command to handle the emails.  why?  it’s easier in my case.

the first thing we need to do is create an appropriate rule to pick up the events.  there are so many sources of information on how to do this that i’ll just provide a link to them.  here you go: http://tinyurl.com/kv9ddg.  shout out to “stefan the stranger” for showing me that site.

here are some things to note.

  • some sources indicate using event description.  if you can get away from doing this, for performance reasons, it’s recommended.
  • parameter 3 holds the group name if you want to do a group name comparison.
  • if you’re searching for multiple events, use a regex statement.
  • if you want to capture the parameter value, you’ll need to push it into a custom field.

here’s the statement i’m using for my criteria:

( ( Event ID Matches regular expression ^(631|632|633|634|635|636|637|638|650|651|655|656|660|661|665|666)$ ) AND ( Parameter 3 Matches wildcard myGroup* ) )

in the last bullet above, i mentioned pushing the parameter to a custom field.  simply change the alert for the responses.  the custom alert field (in my case 1) should contain this string:

$Data/Params/Param[3]$

at this point, you should be picking up the alerts.  if not, keep trying.  :)

 

i was challenged with either having to create multiple notification subscriptions or using a script to handle the notifications.  i chose the latter.  however, either can be managed fairly well.  if you choose to create notification subscriptions, you may want to view this post.

in order to make a script work, we’ll need to create a command channel.  here are the properties you should include:

  • full path
c:\windows\system32\cmd.exe (or whatever is appropriate for you)
  • command line parameters
/c cscript.exe c:\scripts\scom_groupmonitor.vbs "$Data/Context/DataItem/Custom1$" "$Data/Context/DataItem/TimeRaisedLocal$" "$Data/Context/DataItem/AlertDescription$" "$Data/Context/DataItem/AlertName$"
  • startup folder
c:\scripts (or wherever your script is)
image

as you can see, we’re pushing different fields as arguments into the script.  i can’t figure out how to use the values directly from the script, so why not?  anders details this pretty well on his blog.

after that, create your subscriber and your subscription which should be tied to the alert rule you created above.  now, i didn’t detail the contents of the script yet because we had to get through the minutia.  it’s really pretty simple.  the work happens in the select case statement so we’ll go over that part.

Select Case LCase(Left(sGroup,8))    <-- modify this to match the case
Case "myGroup1"
EmailMe "mygroup1@mydomain.com"
Case "myGroup2"
EmailMe "mygroup2@mydomain.com" <-- if there's a match, email
WriteMe "mygroup2@mydomain.com" <-- or log to a file
Case "myGroup3"
EmailMe "mygroup3@mydomain.com"
Case "myGroup4"
EmailMe "mygroup4@mydomain.com"
Case "myGroup5"
EmailMe "mygroup5@mydomain.com"
Case Else
EmailMe "allmygroups@mydomain.com"
End Select

that’s pretty much it.  i marked it with <—.  the top portion of the select case is what you’d modify to match your group name.  in my example, i want to match the first 8 characters.  if my group was myGroup2200, it would match myGroup2.  hope that makes sense.  you’ll notice there’s a “writeme” sub called too.  this is because i had to make sure the thing was working.  long story.

next, modify the sub below for your mail environment.

Sub EmailMe(sRecipient)
Set oMessage = CreateObject("CDO.Message")
oMessage.Subject = sGroup & " - Group Changed" <-- your subject
oMessage.From = "myMOM@mydomain.com" <-- your sender
oMessage.To = sRecipient
oMessage.TextBody = sMessageBody

oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.mydomain.com" <-- your mail server
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
oMessage.Configuration.Fields.Update

oMessage.Send
End Sub

that’s it.  i condensed the list, but my environment has about 30 different cases to build from.  this is why i thought scripting would be the easier approach.  hope you find it useful.  the full script is below.

 

 

'==========================================================================
' NAME: scom_groupmonitor.vbs
' AUTHOR: Marcus Oh
' DATE: 6/23/2009
' COMMENT: Emails SG admins when group changes are detected.
'==========================================================================

' Alert Name - $Data/Context/DataItem/AlertName$
' CustomField1 - $Data/Context/DataItem/Custom1$
' Local Time Raised - $Data/Context/DataItem/TimeRaisedLocal$
' Description - $Data/Context/DataItem/AlertDescription$

sGroup = Wscript.Arguments.Item(0)
sTime = WScript.Arguments.Item(1)
sEventDesc = WScript.Arguments.Item(2)
sAlertName = WScript.Arguments.Item(3)


' Redeem the value of our soul by massaging the description to be legible
myTempString = Split(sEventDesc,"\n \n")
For Each line In myTempString
myNewStuff = myNewStuff & VbCrLf & line
Next
sEventDesc = myNewStuff


sMessageBody = "Time: " & sTime & VbCrLf &_
sAlertName & VbCrLf &_
VbCrLf & sEventDesc

Select Case LCase(Left(sGroup,5))
Case "mygroup1"
EmailMe "mygroup1@mydomain.com"
Case "mygroup2"
EmailMe "mygroup2@mydomain.com"
WriteMe "mygroup2@mydomain.com"
Case "mygroup3"
EmailMe "mygroup3@mydomain.com"
Case "mygroup4"
EmailMe "mygroup4@mydomain.com"
Case "mygroup5"
EmailMe "mygroup5@mydomain.com"
Case Else
EmailMe "allmygroups@mydomain.com"
End Select

Sub EmailMe(sRecipient)
Set oMessage = CreateObject("CDO.Message")
oMessage.Subject = sGroup & " - Group Changed"
oMessage.From = "myMOM@mydomain.com"
oMessage.To = sRecipient
oMessage.TextBody = sMessageBody

oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.mydomain.com"
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
oMessage.Configuration.Fields.Update

oMessage.Send
End Sub

Sub WriteMe(sRecipient)
Dim oFSO, oLogFile

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oLogFile = oFSO.OpenTextFile("GroupMonitor.log", 8, True)

oLogFile.WriteLine(vbcrlf & sRecipient & " : " & sGroup & VbCrLf & sMessageBody)
oLogFile.Close
End Sub

Comments

Popular posts from this blog

using preloadpkgonsite.exe to stage compressed copies to child site distribution points

UPDATE: john marcum sent me a kind email to let me know about a problem he ran into with preloadpkgonsite.exe in the new SCCM Toolkit V2 where under certain conditions, packages will not uncompress.  if you are using the v2 toolkit, PLEASE read this blog post before proceeding.   here’s a scenario that came up on the mssms@lists.myitforum.com mailing list. when confronted with a situation of large packages and wan links, it’s generally best to get the data to the other location without going over the wire. in this case, 75gb. :/ the “how” you get the files there is really not the most important thing to worry about. once they’re there and moved to the appropriate location, preloadpkgonsite.exe is required to install the compressed source files. once done, a status message goes back to the parent server which should stop the upstream server from copying the package source files over the wan to the child site. anyway, if it’s a relatively small amount of packages, you can

How to Identify Applications Using Your Domain Controller

Problem Everyone has been through it. We've all had to retire or replace a domain controller at some point in our checkered collective experiences. While AD provides very intelligent high availability, some applications are just plain dumb. They do not observe site awareness or participate in locating a domain controller. All they want is the name or IP of one domain controller which gets hardcoded in a configuration file somewhere, deeply embedded in some file folder or setting that you are never going to find. How do you look at a DC and decide which applications might be doing it? Packet trace? Logs? Shut it down and wait for screaming? It seems very tedious and nearly impossible. Potential Solution Obviously I wouldn't even bother posting this if I hadn't run across something interesting. :) I ran across something in draftcalled Domain Controller Isolation. Since it's in draft, I don't know that it's published yet. HOWEVER, the concept is based off

sccm: content hash fails to match

back in 2008, I wrote up a little thing about how distribution manager fails to send a package to a distribution point . even though a lot of what I wrote that for was the failure of packages to get delivered to child sites, the result was pretty much the same. when the client tries to run the advertisement with an old package, the result was a failure because of content mismatch. I went through an ordeal recently capturing these exact kinds of failures and corrected quite a number of problems with these packages. the resulting blog post is my effort to capture how these problems were resolved. if nothing else, it's a basic checklist of things you can use.   DETECTION status messages take a look at your status messages. this has to be the easiest way to determine where these problems exist. unfortunately, it requires that a client is already experiencing problems. there are client logs you can examine as well such as cas, but I wasn't even sure I was going to have enough m