Deployment Solution

 View Only

Send Email on DS Job Error 

Jul 24, 2008 04:51 PM

Sometimes Deployment Server jobs are cancelled by the end user for various reasons.

Wouldn't it be nice to get an email if a job was cancelled by the user so you would know right away when it happens instead of having to monitor the Deployment Server or multiple Deployment Servers?

This a very simple process to set up using the error codes in Deployment Server.

First step is to copy the *Send error email job from the Deployment Server samples/scripts/windows folder. Right click the job and choose copy. The go to the bottom of your Jobs folder and paste it in. Now you will have a job called *Send error email. The next thing you want to do is edit the script so it will send an email to you and then run a test so you get the proper information from the email. The script looks like this as default:

'Send mail showing that there was an error.
'vbscript
' Description: This will send an email message to the specified 
'	  recipient using the SMTP server and account to 
'	  indicate an error with the Job that was executed.
'---------------------------------------------------------------------------------------------------
Dim Conf
Dim Message 
Dim SMTPServer
Dim FromName
Dim ToName
Dim SendUsername
Dim SendPassword
Const SendUsingPort = 2

' Set the variables used to send the message
SMTPServer = "SMTPSERVER" 
FromName = "user@domain.com" 
ToName = "user@domain.com" 

' Setup the configuration for the message to use
Set Conf = CreateObject("CDO.Configuration")
With Conf.Fields
 .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = SendUsingPort
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
 .Update
End With
 
'Setup the message
Set Message = CreateObject("CDO.Message")
With Message
 Set .Configuration = Conf
 Dim JobName
 JobName = """%CALLINGJOBNAME%"""
 
 'Set email adress, subject And body
 .To = ToName
 .Subject = "%COMPNAME% " & JobName & " job Failed"
 .TextBody = "DS Job " & JobName &" for " & "%COMPNAME%" & " Failed at " & Date & " " & Time
 .From = FromName
 .Send
End With

You will need to make changes to this part:

' Set the variables used to send the message
SMTPServer = "SMTPSERVER" Your email server. Usually just an IP address.
FromName = "user@domain.com" I like to use the DS Servername.
ToName = "user@domain.com" Who you want the email to go to.

You can now edit how the email will look by changing the entries under 'Set email address, subject and body'. I changed mine for this just to state the the job was cancelled by the user as we are going to send an email only if it was cancelled. This is master return code 5 and we will get to that shortly.

My whole script to send the email reads:

'Send mail showing that there was an error.
'vbscript
' Description: This will send an email message to the specified 
'	  recipient using the SMTP server and account to 
'	  indicate an error with the Job that was executed.
'---------------------------------------------------------------------------------------------------
Dim Conf
Dim Message 
Dim SMTPServer
Dim FromName
Dim ToName
Dim SendUsername
Dim SendPassword
Const SendUsingPort = 2

' Set the variables used to send the message
SMTPServer = "xx.xx.xx.xx" 
FromName = "AltirisServer@noreply.com" 
ToName = "xxxxxx@xxxxxx.net" 

' Setup the configuration for the message to use
Set Conf = CreateObject("CDO.Configuration")
With Conf.Fields
 .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = SendUsingPort
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
 .Update
End With
 
'Setup the message
Set Message = CreateObject("CDO.Message")
With Message
 Set .Configuration = Conf
 Dim JobName
 JobName = """%CALLINGJOBNAME%"""
 
 'Set email adress, subject And body
 .To = ToName
 .Subject = "%COMPNAME% " & JobName & " job Failed"
 .TextBody = "DS Job " & JobName &" for " & "%COMPNAME%" & " was cancelled by the user " & Date & " " & Time
 .From = FromName
 .Send
End With

Ok now take this job you created and test it by sending it to yourself.
You should now get an email that looks like this.

Make any changes you like and then we will go to adding this as an error code condition.

To test this I made a simple job called RUN TEST on my server. On this job I added run script and just did a DIR command and a PAUSE.

Choose Next and use the defaults on this next page until we get to the Return Codes screen.

Click on the Master Return Codes button. It should be empty right now so go ahead and choose Add.

You will be presented with a blank return code we can edit.

In the Code section put in the number 5. In the Response choose the dropdown to select a job and click the *send error email job and hit OK.

You now have created a Master Return Code with a condition on it. This will always show up on your master return code list.

Your test job will now show the Master Return Code 5 as a condition of the job.

Now send this job to yourself and since we are running a DIR command and then pausing we can stop the job by exiting the DOS prompt and it should send you an email stating the job was cancelled by the end user.

The email you get now if you cancel the job will now tell you the job name and that it was cancelled.

Now you will know right away if a job is cancelled by the user and can do whatever is necessary to get this job running back on track.

Statistics
0 Favorited
0 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

Aug 15, 2008 08:13 AM

Once you start using this, it's amazing how many uses you find for it and reasons to queue up this job.

Related Entries and Links

No Related Resource entered.