Have you ever thought on creating Alerts directly from a mail? Or Send a mail to your OpsMgr to raise an alert in your Operations Manager?
A few weeks ago I was talking with a guy participating on one of the Advanced OpsMgr courses, his existing monitoring environment currently delivered an mail to a group mailbox in which they used to react and resolve issues from a Nagios/IPMonitor installation. But what he really would like to was gather all issues in the Operation Manager Console, after a quick talk with Jakob Svendsen https://blog.ctglobalservices.com/jgs/outlook-2010-auto-export-body-of-new-e-mails/ he came up with a “How To” create text files directly from Outlook. I will also use Jakob’s step by step Outlook configuration as the first step in this three step configuration:
First the Prerequisite:
· Operations Manager 2007
· A client or server with an OpsMgr agent and Outlook 2007/2010
· Notepad (Or your favorite vbs editor)
In short:
1) Configure Outlook to save a text file every time a mail arrives
2) Create a Timed Rule which gather all text files and raise Alerts
3) Create an Event Monitor which react on the alert create in step 2.
1. Outlook Configuration:
1. Enable Developer Ribbon to be able to create scripts
2. Open visual Basic
3. Select “ThisOutlookSession”
4. Type/ this Sub into Visual Basic. Changed the strExportPath to the folder you want to use.
Sub SaveMessageOnRule(Item As Outlook.MailItem)
Dim strExportPath As String
strExportPath = “C:\Temp\Mails\”
Dim FileName As String
FileName = strExportPath & Replace(Replace(Replace(Now & “_” & Item.EntryID & “.txt”, “:”, “_”), “-“, “_”), ” “, “_”) ‘Create filename and path, replace : with _, …
Dim FileNum As Integer
FileNum = FreeFile ‘ next file number
Open FileName For Output As #FileNum ‘ creates the file if it doesn’t exist
Print #FileNum, Item.Body ‘ write information at the end of the text file
Close #FileNum ‘ close the file
End Sub
5. Create rule in outlook
6. Select the coditions you want. Or none to process all emails
7. Select “run as Script” in the Select actions window, and choose the sub you have just created
8. Define exceptions if you have any, otherwise leave it blank.
9. Give your rule a name and save it.
10. You are now ready to setup the managementpack – Test it and be sure you get an email in the specified folder.
2. Create a Timed Script Rule
After this is done create a Timed Script Rule in Operations Manager by following this guide:
And the script to paste in the code window: (feel free to make it your way)
Option Explicit
On Error Resume Next
‘=========================================
‘Declare Variables
‘=========================================
Dim objAPI, objBag, objFSO, strTargetFolder, objFolder
Dim folderIdx, objFile, strDoneFile, arrFileLines
‘=========================================
‘Declare Constants
‘=========================================
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4
‘=========================================
‘Create Objects
‘=========================================
Set objAPI = CreateObject(“MOM.ScriptAPI”)
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
strTargetFolder = “c:\Temp\Mails”
Set objFolder = objFSO.GetFolder(strTargetFolder)
‘=========================================
‘Intelligents…
‘=========================================
IF Err.Number > 0 Then
Call objAPI.LogScriptEvent(“ReadMail.vbs “,0, EVENT_TYPE_ERROR ,”Folder ” & strTargetFolder & ” was not found.”)
Else
For each FolderIdx In objFolder.Files
Set objFile = objFSO.OpenTextFile(FolderIdx.Path, 1)
Set strDoneFile = objFSO.GetFile(FolderIdx.Path)
arrFileLines = objFile.ReadAll
Call objAPI.LogScriptEvent(“Test From ErrorMail”,666, EVENT_TYPE_Warning, arrFileLines)
objFile.Close
strDoneFile.Delete
Next
End IF
3. Create an Alert Generating Event Rule
Create a new rule – remember the Management Pack
Please, disable the rule and create an override afterwards.
And the override on the Windows/Outlook client:
And Voila – now you recieve all alerts from outlook, and the best thing is that you yourself can create Alerts directly by emailen the user. So in need for any Alerts
Have a nice day
Kåre
Interesting use case. Thanks for the contribution.
Kare,
Was wondering if there are any outputs for errors on the VB(outlook)? I have set up exactly like you have demonstrated and steps 2 and 3 are working(I create a fake .txt file in my location, script runs and creates alert and clears folder). For some reason I am not able to get the VB on the outlook working and I have no clue where to start troubleshooting as I haven’t been able to locate any errors. Please help! Thanks again as well for all of your great posts!
Thanks,
Matt
Hi Matt and thanks for the flowers – could you try to paste the following code into your Outlook VBA:
Sub SaveMessageOnRule(Item As Outlook.MailItem)
Dim strExportPath As String
strExportPath = “C:TempMails”
Dim FileName As String
FileName = strExportPath & Replace(Replace(Replace(Now & “_” & Item.EntryID & “.txt”, “:”, “_”), “-“, “_”), ” “, “_”)
Dim FileNum As Integer
FileNum = FreeFile
Open FileName For Output As #FileNum
Print #FileNum, Item.Body
Close #FileNum
End Sub
Hi
thanks for your contribution,
i don’t see in the SCOM script CheckForAlert.vbs why there is a call to readmail.vbs … nor what is the script associated to it
“Call objAPI.LogScriptEvent(“ReadMail.vbs ”
Thanks a lot for your help
Frederic
The LogScriptEvent is a method for writing to the Eventlog so ReadMail.vbs is just a plain text which you can see in the OpsMgr Event log.
🙂
Kåre
i see 🙂 thanks for your input 🙂
Frederic.