Event log

Azathoth (13 posts)
May 31, 2005 03:01 AM
Accepted Answer

Hi,

Is it posisble to write to the Application eventlog of the adTempus server if a job is failed?

If that's not possible, then how can i find the current job status and job name from within a script.
I want to make 1 script, and use it as a response when the job has failed. With a script i made it possible (using an Active-X DLL) to write events, but right now I don't know the job name and/or status.

gr,
Jeroen

Administrator Staff (65 posts)
June 1, 2005 07:41 PM
Accepted Answer
adTempus cannot be made to write to the Event Log.

From within a script, you can get the name of the current job from the ADTJobDescription environment variable. For example:
      Environment("ADTJobDescription")
will return the name of the job.

See www.arcanadev.com/support/K00000189 for a full list of the special environment variables that are available.

To get the status, you will have to use the adTempus API to retrieve the job and get its status. The following VBScript can be run from a response to get the calling job's name and status code:

dim app
dim session
dim job
dim jobName
dim jobStatus

     'Create the adTempus application object
     set app=CreateObject("adtempus.application")
     
     'Create a new session to the local adTempus server
     set session=app.Connect("","")

     'Get the current job
     set job=session.getobject(Environment("ADTJobOID"))
     
     jobName=job.name

     'get the status code for the job. See JobStatusEnum in the adTempus API reference for a list of values     
     jobStatus=job.GetStatus.Status

For more information on the API, see the API documentation available at www.arcanadev.com/adtempus/api/documentation. You'll need to refer to the topic for the JobStatusEnum for the list of possible status codes for the job.administrator38504.9057060185
Azathoth (13 posts)
June 2, 2005 05:20 AM
Accepted Answer

Thank you very much for the example script, this was exactly what i needed.

I found a (free) Active-X DLL for writing to the eventlog. I combined that script, and yours into a "shared script" in adTempus. Then I call that script from a response, and that's it.

Here is the script for anyone who need the same:

 


' By: Azathoth

' Version: 1.0
' Last update: 02/06/2005
' Description: Writes the failed adTempus jobs to the eventlog.
'
' This script uses the (free) STMAdmin.dll to write to the eventlog.
' You can download it here:
' http://cwashington.netreach.net/downloads/com/event_log_manager.zip

' Constants for Event Logging
Const EVENT_SUCCESS = 0
Const EVENT_ERROR = 1
Const EVENT_WARNING = 2
Const EVENT_INFORMATION = 4
' Declarables
Dim objAdTempus
Dim objSession
Dim objJob
Dim strJobName
Dim intJobStatus
Dim objEventLog
Dim intEventID
Dim blnError
Dim strGroupName
Dim strGroupDescription

 ' Create the adTempus Application object
 set objAdTempus = CreateObject("adtempus.Application")
     
 ' Create a new objSession to the local adTempus server
 set objSession = objAdTempus.Connect("","")
 ' Get the current job 
 set objJob = objSession.getobject(Environment("ADTJobOID"))
     
 strJobName = objJob.name
 ' Get the status code for the job. See intJobStatusEnum in the adTempus API reference for a list of values      
 intJobStatus = objJob.GetStatus.Status
 
 ' Get the Group name
 strGroupName = objJob.Group.Name
 strGroupDescription = objJob.Group.Description

' Default assume it' s an error
blnError = True
Select Case intJobStatus
 Case &h80000001
  ' No Error
  blnError = False
  strintJobStatus = "The job or step completed successfully."
 Case &H40000002
  strintJobStatus = "The step was killed because it exceeded its maximum run time."
 Case &h50001
  strintJobStatus = "The job or step was aborted by a user or JobControlTask."  
 Case &h40010001
  strintJobStatus = "The trigger could not be evaluated."  
 Case &h40040001
  strintJobStatus = "The step failed the task could not be executed (e.g., a program could not be executed)."  
 Case &h40030001
  strintJobStatus = "The job or step failed because a resource failed."  
 Case &h40020001
  strintJobStatus = "The job or step failed because a condition failed."  
 Case &h40000001
  strintJobStatus = "The job or step failed."  
 Case &h30030001
  strintJobStatus = "The job or step is waiting for one or more resources to be available."  
 Case &h30020001
  strintJobStatus = "The job or step is waiting for one or more conditions to be satisfied."  
 Case &h20050001
  strintJobStatus = "The job or step is being aborted."  
 Case &h20000003
  strintJobStatus = "The step is in the process of killing its process because it has exceeded its run time."  
 Case &h20000002
  strintJobStatus = "The job or step is running."  
 Case &h20000001
  strintJobStatus = "The job or step is starting."  
 Case &h10040001
  strintJobStatus = "The job is waiting for a previous instance to finish."  
 Case &h10010001
  strintJobStatus = "The job is waiting for a trigger."  
 Case &h5
  strintJobStatus = "One or more conditions was not met."  
 Case &h4
  strintJobStatus = "The job or step was skipped."  
 Case &h2
  strintJobStatus = "The job or step was abandoned (because adTempus shut down while job was executing)."  
 Case &h1
  strintJobStatus = "The step was not run."  
 Case &h0
  strintJobStatus = "Status unknown, or has never been run."
 Case Else
  strintJobStatus = "Status unknown: " & intJobStatus
End Select

' Is it an error?
If blnError Then
 Set objEventLog = CreateObject("STMAdmin.EventLog")
 objEventLog.ReportEvent "adTempus", 1001, vbcrlf & vbcrlf & "Status: The job " & chr(34) & strJobName & chr(34) & " failed." & vbcrlf & "Reason: " & strintJobStatus & vbcrlf & "Group Name: " & strGroupName & vbcrlf & "Group Description: " & strGroupDescription, EVENT_ERROR
' Else
'  Set objEventLog = CreateObject("STMAdmin.EventLog")
'  objEventLog.ReportEvent "adTempus", 1000, "Status: The job" & chr(34) & strJobName & chr(34) & " completed successfully" & vbcrlf & "Group Name: " & strGroupName & vbcrlf & "Group Description: " & strGroupDescription, EVENT_SUCCESS
End if

Azathoth38505.3250578704

Replies are disabled for this topic.