Integrate OpManager with Freshservice to track and process your alerts as aggregated records in Freshservice to quickly understand and resolve your issues.


Configuration in Freshservice:


Step 1:

Head to the Admin panel, scroll down to IT Operations Management, and select Monitoring Tools

If your account has more than one workspace, navigate to Admin > {Worskpace Name} > IT Operations Management> Monitoring Tools.



Step 2:

You are now on the Monitoring Tools list page. Select Add monitoring tool to add a new integration.




Step 3

You will see a list of pre-configured integrations, the gateway to custom integration using webhooks, and the option to use email as a channel for alerts. Select OpManager.


Step 4

Get the Endpoint URL and the Auth key for OpManager by following the integration setup.


Configuration in OpManager using Webhooks:

1. Login to OpManager and navigate to Settings -> Notifications -> Notification Profiles.

2. From the Notification Profile page, create a new profile and choose “Invoke a webhook”.

3. Choose “POST” from  the Hook URL drop down and copy paste the Freshservcie integration to the text box after drop-down.

4. Change the Data Type as “raw”

5. Change the Payload Type as “JSON”

6. Past the below context in the Body Content

{
          "resource": "$displayName",
          "metric_name":  "$MonitorField(monitorName)",
           "severity" :  "$stringseverity",
           "message":  "$message",
          "category":  "$category",
           "event_type":   "$eventType",
           "entity": "$entity",
           "timestamp": "$strModTime",
          "value":  "$lastPolledValue",
          "ip_address":  "$DeviceField(ipAddress)",
           "device_type":  "$DeviceField(type)"
}

7. Add new Request Header with the Header Name as “Authorization” and copy the Authorization Key from Freshservice Integration to Header Value.

8. Set your own criteria

9. Select devices

10. Configure the Time Window, Delayed Trigger, and Recurring Trigger.

11. Test the integration by clicking “Test Alert''. This should send a test alert to Freshservice.

12. Save the above changes and close it.

13. OpManager should be able to send alerts to Freshservice and resolve it automatically.


Configuration in OpManager using Powershell script:

Prerequisite:

This integration is possible only for OpManager running on a Windows machine

1. For the Windows version, Powershell Script has to be available in the server/ machine where OpManager is installed.

2. Powershell version 4 or above must be available in the windows server. 

3. Powershell must have execute (RemoteSigned/Unrestricted) privilege. 

4. Copy and paste the below script to a text file and set the extension as .ps1 to create a powershell script for sending the notification.

5. In the script, replace the Auth token and Endpoint URL with the values copied from Freshservice


# This will send a REST api request to Freshservice AMS module.
# metric_name, resource and entity combination forms the business key of the alert.
# amsAuthKey has to be replaced with the value copied from Freshservice
# amsURL: has to be replaced with the endpoint URL copied from Freshservice
 
#input parameters from Webhook/script action
Param(
  [string]$resource,
  [string]$metric_name,
  [string]$severity,
  [string]$message,
  [string]$category,
  [string]$event_type,
  [string]$entity,
  [string]$value,
  [string]$ip_address,
  [string]$timestamp,
  [string]$device_type,
  [string]$amsURL = "https://testbyruban.alerts.freshcmdb.com/integrations/53545/alerts?auth-key=eyJhbGciOiJIUzI1NiJ9.eyJhX2lkIjo1MTMzLCJzX2lkIjoxMCwidHMiOjE2Njc4ODA2NDAuMzM2MDYzNH0.PAmVagJHLMiewkaBsjmoypKPIzVhOOGxC2J4r2kR3k0"
)
try {
  Write-Host "FS:Starting..."
 
  if ($metric_name -eq '') {
    $metric_name = $entity
  }
 
  Write-Host "FS:After check..."
 
  #RestAPI headers
  $AuthHeader = @{
    "Content-Type"  = "application/json";
  }
 
  Write-Host "FS:After header construction..."
 
  #payload construction
  $jsondata = @{
    resource    = $resource;
    metric_name = $metric_name;
    severity    = $severity;
    message     = $message;
    category    = $category;
    event_type  = $event_type;
    entity      = $entity;
    value       = $value;
    ip_address  = $ip_address;
    timestamp   = $timestamp;
    device_type = $device_type;
    description = $message;
  }
 
  Write-Host "FS:After payload construction..."
 
  #remove empty keys
  ($jsondata.GetEnumerator() | ? { -not $_.Value }) | % { $jsondata.Remove($_.Name) }
 
  Write-Host "FS:After removing empty entities..."
 
  #convert to json object
  $Body = ConvertTo-Json $jsondata
  Write-Host $Body
 
  #To Fix UnauthorizedAccess due to TLS protocol version
  [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
 
  # Freshservice AMS restapi call
  Invoke-RestMethod -Method Post -Uri $amsURL -Headers $AuthHeader -Body $Body;
  exit 0;
}
Catch {
  $ErrorMessage = $_.Exception.Message
  Write-Host "Error: " $ErrorMessage
}



Add Notification Profile 

  1. Login to OpManager Web UI.

  2. Go to Settings -> Notification menu. Click the “Add” button to create a new Notification Profile.

  3. Select “Run Program” as the notification profile type.

  1.  Add Command Name & Program Arguments as given below:


Command Name:

The command name should be in the following format 

Powershell.exe -file <file path of the powershell script created for notification> 

For ex:

     powershell.exe -file D:\Build\Opmanager_notification\AlertNotification.ps1


Arguments:


     -resource "$displayName" -metric_name  "$MonitorField(monitorName)" -severity  "$stringseverity" -message  "$message" -category  "$category" -event_type  "$eventType" -entity "$entity" -timestamp "$strModTime" -value "$lastPolledValue"  -ip_address "$DeviceField(ipAddress)" -device_type "$DeviceField(type)"


  1. Click Next and choose the criteria applicable for the notification to execute.

  2. Click Next after the required options are selected.

  3. In  “Associate Notification Profile”,  choose the devices or URLs applicable. In our case, we are selecting the monitoring URL. 

  4. Click Next and move to the next screen “Time Window”. By default, we are monitoring 24x7.

  5. Click Next. “Run Program” Summary Page will be displayed. 


Add profile name and Save the page. 


To test the notification profile, click “Test Action” button.

Now everything is set to receive alert in Freshservice.


Troubleshooting:

  1. Incase if the alert did not get created, test the PS script file by executing in command prompt:

In the example below, replace the powershell.exe path and notification script path accordingly.

C:\integration\opmanager_notification> powershell.exe -file C:\integration\opmanager_notification\AlertNotification.ps1 -resource "Mailserver1" -metric_name  "CPUUtilization" -message  "CPU greater than 80%" -category  "Poll" -event_type  "Threshold" -entity "MailServer1 CPU2" -timestamp "123455444" -value "80%"  -ip_address "10.10.1.108" -device_type "Server" -severity  "Critical"


    2. If the powershell script does not get executed, then the following has to be run in the command prompt

PS >  Set-ExecutionPolicy RemoteSigned –Force

PS > start-job { Set-ExecutionPolicy RemoteSigned -Force } -RunAs32