0 votes

Is there a way to email a notification when there are errors? Our human resources will often delay or forget to let our IT staff know that there was an error on the web interface.

by (290 points)

1 Answer

0 votes
by (216k points)
selected by
Best answer

Hello,

It will be hard to configure a workflow to send an e-mail notification when any error occurs, however it is possible to configure a Scheduled Task that will run, say, once a day and will send you a report on all errors that occurred during a day. Will such a solution suit your needs? If so, we will provide you with more detailed instructions.

0

Having a scheduled task will work out nicely. I look forward to the details on how to do this.

0

Hello,

To create such a Scheduled Task:

  1. Create a new Scheduled Task.

  2. On the 2nd step of the Create Scheduled Task wizard, configure it to run daily, say, at the end of the work day.

  3. On the 3rd step, select the Show all object types option.

  4. Select the Domain-DNS object type. Running the Task on a domain allows to run the script only once per a Task run.

  5. On the 4th step of the wizard, add the Run a program or PowerShell script action and paste the following script in the Script field:

     $numDays = 1 # set to 0 to output all records
     $to = "recipient@domain.com" # TODO: modify me
     $subject = "Adaxes errors for the last $numDays days" # TODO: modify me
     $htmlReportHeader = @"
     <b>Adaxes errors for the last $numDays days</b><br/><br/>
     <table border="1">
         <tr>
             <th>Start Time</th>
             <th>Completion Time</th>
             <th>Initiator</th>
             <th>Target Object</th>
             <th>Target Object Type</th>
             <th>Operation</th>
             <th>Execution Log</th>
         </tr>
     "@ # TODO: modify me
     $htmlReportFooter = "<hr /><p><i>Please do not reply to this e-mail, it has been sent to you for notification purposes only.</i></p>" # TODO: modify me
    
     function GetExecutionLog ($logEntryCollection, $executionLog)
     {
         $executionLog += "<ul>"
         foreach ($logEntry in $logEntryCollection)
         {
             # Get the operation info
             $type = $logEntry.Type
             $message = $logEntry.Message
             $source = $logEntry.Source
    
             # Build report record
             $messageBuilder = ""
             if (-not([System.String]::IsNullOrEmpty($source)))
             {
                 # Add the source to the message
                 $messageBuilder += "$source`: "
             }
             $messageBuilder += "$type - $message"
    
             # Encode all HTML tags
             $messageBuilder = [System.Web.HttpUtility]::HtmlEncode($messageBuilder)
    
             # Add the message to the report
             $executionLog += "<li>$messageBuilder"
    
             # Add subentries, if any
             $subEntries = $logEntry.SubEntries
             if ($subEntries.Count -ne 0)
             {
                 $executionLog = GetExecutionLog $subEntries $executionLog
             }
             $executionLog += "</li>"
         }
         $executionLog += "</ul>"
         return $executionLog
     }
    
     # Bind to the Service Log
     $path = $Context.GetWellKnownContainerPath("ServiceLog")
     $serviceLog = $Context.BindToObject($path)
    
     # Set the start and end dates
     $generalLog = $serviceLog.GeneralLog
     if ($numDays -ne 0)
     {
        $generalLog.StartDateTime = (Get-Date).AddDays(-$numDays)
        $generalLog.EndDateTime = Get-Date
     }
    
     # Get the log records
     $log = $generalLog.Log
     $records = $log.GetPage(0)
    
     $errorCount = 0
     foreach ($record in $records)
     {
         if (($record.State -eq "OPERATION_STATE_FAILED_CAN_CONTINUE") -or ($record.State -eq "OPERATION_STATE_FAILED_NO_CONTINUE"))
         {
             # Add the log record to the report
             $recordStartTime = $record.StartTime 
             $recordCompletionTime = $record.CompletionTime
             $recordInitiatorName = $record.Initiator.Name
             $recordTargetObjectName = $record.TargetObjectName
             $recordTargetObjectType = $record.TargetObjectType
             $recordDescription = $record.Description
    
             # Get Execution Log
             $executionLogEntries = $record.GetExecutionLog()
             if ($executionLogEntries.Count -eq 0)
             {
                 $executionLog = "Execution Log is empty"
             }
             else
             {
                 # Add Execution Log to the report
                 $executionLog = GetExecutionLog $executionLogEntries ""
             }
             $htmlReportHeader += "<tr valign='top'><td>$recordStartTime</td><td>$recordCompletionTime</td><td>$recordInitiatorName</td><td>$recordTargetObjectName</td><td>$recordTargetObjectType</td><td>$recordDescription</td><td>$executionLog</td></tr>"
    
             $errorCount++
         }
     }
    
     if ($errorCount -ne 0)
     {
         # Build HTML report
         $htmlBody = $htmlReportHeader + "</table><p>Total Errors: $errorCount</p>" + $htmlReportFooter
    
         # Send report
         $Context.SendMail($to, $subject, $NULL, $htmlBody)
     }
    
  6. In the script, customize the following to meet your requirements:

    • $to - specifies the recipient of the report,
    • $subject - specifies the email message subject,
    • $htmlReportHeader - specifies the report header,
    • $htmlReportFooter - specifies the report footer.
  7. Add a short description for the script and click OK.

  8. On the 5th step, assign the Scheduled Task over any of your AD domains.

  9. Click Finish.

0

Wow, this works perfectly! Thank you!

Related questions

0 votes
1 answer

Is there a way to have the Create User trigger to run a command to trigger the update user flag/trigger to be hit? The goal is to have specific Create User tasks to also go through the same tasks as the Update user.

asked Mar 2, 2023 by mobosys (290 points)
0 votes
1 answer

How can i différenciante the two user without opening each one of them ?

asked Jan 20, 2023 by eric.lebrun (20 points)
0 votes
1 answer

I would like users to use Adaxes to add themselves or others to a group, but instead of it just working, it has to go thru an approval process and be approved by the group owner before they are added. Thanks!

asked Jun 30, 2021 by RayBilyk (230 points)
0 votes
1 answer

We are evaluating the product and would like to let users of AD to change password in self service page. We would like to set a 90 days change password policy, ... self service page? Is it achievable (with customization and batch program)? Thanks in advance.

asked Apr 27, 2020 by eric (20 points)
0 votes
1 answer

My security team is looking to do a security review and would like the vendor to fill out a questionnaire.

asked Aug 25, 2023 by LarrySargent (20 points)
3,346 questions
3,047 answers
7,772 comments
544,972 users