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 (190 points)

1 Answer

0 votes
by (215k 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

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 (220 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

We have a process that when a new user is created they are emailed their username and apssword. If the user is in an Admin Group they are then sent an email with some PDFs ... you can send emails, but am unable to see where it could attach files to the email?

asked Sep 3, 2020 by dknapp (100 points)
0 votes
1 answer

Hello, I need some advice. I'd like to create a specific After user creation action, but I don't know exactly how. In our environment a new user need to assign a MS365 ... 313/create-user-mailbox-in-office-365 Will it work in 2020? Thank you for your answer.

asked Dec 14, 2020 by the7thever (50 points)
0 votes
1 answer

I am attempting to run a command using powershell. The command is using Google Apps Manager (GAM). Whenever the command runs and is successful, Powershell reports that it has ... . The issue lies with the software I am using and how it works with Powershell.

asked Nov 12, 2014 by mobosys (190 points)
2,803 questions
2,538 answers
6,609 comments
63,890 users