Home » Scripts (Page 4)

Category Archives: Scripts

Timed Script Two State Monitor

This is an example how to use a timed script two state monitor to monitor a file exists. If the file exists the monitor is healthy.

  1. Create a Timed Script Two State Monitor, input suitable name, scheudle, target and description.
  2. Input this script below
  3. As unhealthy expression input “Property[@Name=’Status’] equals Error”
  4. As healthy expression input “Property[@Name=’Status’] equals Ok”
  5. Configure alerts and then your done.

Dim oAPI, oBag
Set oAPI = CreateObject(“MOM.ScriptAPI”)
Set oBag = oAPI.CreatePropertyBag()
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
strFile = “C:\myfile.log”
If objFSO.FileExists(strFile) Then
Call oBag.AddValue(“Status”,”Ok”)
Call oAPI.Return(oBag)
Else
Call oBag.AddValue(“Status”,”Error”)
Call oAPI.Return(oBag)
End If

Files created last X hours including Y in the filename

This is a script that checks if there is a new file, contains a keyword, and that the file has been created last X hours. For example if you have a couple of servers uploading files every hours, you can check with this script if all servers have uploaded a new file the last hour. Even if the filename is not always the same, for example many applications add a timestamp to the filename like server05_20081012.
Configuration.txt contains all keywords that should be included in a filename. Contoso_filecheck.hta is a GUI that you can use to add keyword, delete keywords and show current keywords. contoso_filechecker.vbs is the script that does the filecheck.

  1. The script counts number of files in the folder, that was created last X hours (default folder is C:\LogFiles and default time is 24 hours)
  2. The script creates an array of all the files that was created last X hours
  3. The script loops all selected files and checks if the keyword is in the filename. It then moves on to the next keyword and loops all selected filenames.
  4. If the keyword, for example a server1, is in Configuration.txt but there is no file including server1 created last 24 hours, a local event will be created including the time configuration and the keyword.
  5. You can configure MOM 2005 or Ops Mgr to pickup these events and generate an alert.

Download the script here.

Groups to Classes

This management pack allows security groups in Active Directory to be used to discover classes in Operations Manager 2007. For example if you already have your servers divied into security groups in Active Directory you can use populate classes from those groups and use the same in Operations Manager 2007 for targeting.This management pack needs to be adapt to your environment before you can use it. I recommend you to do that in the Authoring Console.

The management pack includes two classes, Contoso.GRP2CL.Fileservers and Contoso.GRP2CL.AppServers. Both these classes have one discovery rule each. The discover rules use script to check if the local machine is member of a specified security group in Active Directory. If they are, they create a instance of the class. The LDAP path is configure in the script. You should also change the discovery schedule, default time is every two minute.

The management pack also includes two state views to show which machines that are in the classes.

Every two minute it runs a script on all windows servers to see if they are member of a security group in Active Directory. If they are, a instance of the class is created.

Download the package here. Please note that this is a sample/idea, make sure to test and review it in a testenvironment.

Script: Notification Based on Keyword

I have written a script to show an idea how to get notification based on keywords. I have a power shell script that checks new alerts for the keyword and sends notification. This is occurs outside of the Ops Mgr console, so you will not see this under recipients or subscriptions in the console. The power shell scripts get both keywords and recipients from a configuration file. After a notification is sent the custom field 1 is updated on the alert, so the script will not send multiple notification for the same alert.

You can modify this script to include more attributs from an alert, with default settings it is only searching the alert description.

All information is included in the readme file.

Download the package here.

Script: Shares Creation

Earlier I have post scripts to check network shares, if they are available over the network. This script is also working with shares, it verify if all shares on the machine is approved. Unfortunately we don´t have a central database with all configuration yet but in this example I have solved that with a file on the agent managed machine, including the names of all approved shares.

This script lists all shares, it compare them with share names in a local file. If the share is not in the local file a local event will be generated with the share name and the path to the shared folder. You can pick up that event with Ops Mgr or MOM and generate an alert.

Download there script here

Set Resolution State Automatic

This script will change the resolution state. You can schedule this script to run every X minute, it will then update the resolution state for new alerts. For example set all alerts including *SQL* to resolution state “Assigned to SQL team”. Fairly simple but it can save you some time, instead of changing the resolution state manually or re-configure all rules and monitors to generate alerts with another resolution state.

You can download the script here

Check Registry Value

I have seen a lot of questions and discussions about monitoring registry values. You can do this with a script. I have written a script that reads a binary value out of the registry and check if the value is the same as the script says it should be, if not it will generate a local event, that Ops Mgr or MOM can pickup and generate an alert on. You can download the script here. You can download the script here. If you instead want to store the value in a textfile, you can see a lot of examples of that here.

For the registry reading part there are more examples here, for example how to read other registry object types.

Group membership based on disk device name – part II

Sometimes you need to include two or more volumes in a group.

  1. Create a new group.
  2. On the “Dynamic Members” tab select “Windows Logical Hardware Component” as class and click Add
  3. Right-click “AND group for Windows Logical Hardware Component…” and select “Switch to Or Group” from the context menu.
  4. Select “Device Name” as property, select Equals as Operator and input the volume name as value, for example C:
  5. Click Insert and select Or Group
  6. In the new OR group, select “Device Name” as property, select Equals as Operator and input the volume name as value, for example E:
  7. Click Ok and close the group wizard

 The formula should look like this:

( Object is Windows Logical Hardware Component AND ( Device Name Equals C: ) OR ( Device Name Equals E: ))

Ideas about FTP monitoring

You can monitor a IIS FTP site with the Internet Information Services (IIS) Management Pack. But that management pack only monitor the FTP from the server side. I received a couple of questions how to monitor a FTP from the client side. You can do that with a vbscript, but if you are not that into scripting you can solve it like this:

You can setup a port check. TCP Port check easy to add with the monitoring wizard under management pack templates.

You can also create a FTP.EXE script that logon to your FTP server and perform a number of commands. ftp.exe is a built-in FTP tool in Windows. If you run it with the -s: parameter you can specify a script. You can also use the -d parameter to turn on debug and then the dump the result to a logfile with >>ftpcheck.log. That logfile you can check with a rule or monitor from Ops Mgr. Example

ftp.exe -d -s:ftpscript.ftp >>ftp_log.log

You can run the complete command from a Timed Commands/Execute a command rule. You can then create a Alert Generating Rules/Event Based/Generic Text Log (Alert) rule to monitor that ftp_log.log file. In this post you can read how to setup a rule to check a logfile. Your ftpscript.ftp file can look like this

open 10.1.1.1
loginname
Password
binary
send contoso-test-file.txt
get contoso-test-file.txt
bye

As you can see, it is normal FTP commands inside that file. If you want to only test download a file from a FTP and dont want to check the ftp_log.txt file, you can check when the downloaded file was last updated, according to this post. You can also use this script to search your logfile for words, and generate events.

Check passwords about to expire

I have written a small script that check if account passwords are about to expire. If they are, you get a event in the local event viewer. You can pick up that event with Ops Mgr and MOM and then generate a alert for your operators and/or administrators. You can download the script here.

Default settings are that you will get a event if the password will expire within 20 days and the script checks all user objects within this OU OU=Service Accounts,OU=Contoso EMEA,DC=emea,DC=corp,DC=contoso,DC=localÂ