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:

  • Click on Admin > Alert Profiles > Create a New Alert Profile or open an existing Alert Profile.
  • Click on “Add Integration” to select the tool to integrate with.
  • Select “OpManager” in the tool selection page. 
  • Get the Endpoint URL and the Auth key for OpManager by following the integration setup.


Configuration in OpManager:

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 severity parameters are mandatory.
# metric_name, resource and entity combination forms the business key of the alert. 
# auth-key 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 = " ",
  [string]$authkey = " "
)

if ($metric_name -eq '') {
  $metric_name = $entity
}

#RestAPI headers
$AuthHeader = @{
  "Content-Type"  = "application/json";
  "Authorization" = "auth-key " + $authkey
}

#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;
}

#remove empty keys
($jsondata.GetEnumerator() | ? { -not $_.Value }) | % { $jsondata.Remove($_.Name) }

#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
try {
  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