Skip to content

Commit 7ce4242

Browse files
authored
Merge pull request #126 from davidctm/master
doc update
2 parents e087397 + 42519e3 commit 7ce4242

File tree

8 files changed

+276
-13
lines changed

8 files changed

+276
-13
lines changed

helix-control-m/2-external-monitoring-tools-examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# BMC Helix Control-M API - External Monitoring Tools Examples
22

3-
This folder contains sample scripts that can be used to transfer alerts to external tools, such as an event management system or a monitoring solution.
3+
This folder contains sample scripts that can be used to send BMC Helix Control-M alerts to external applications, such as event management systems, monitoring tools or ITSM solutions.
44

55
## Description
66

helix-control-m/2-external-monitoring-tools-examples/alerts-data-as-variables/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
## Description
22

3-
This Linux (bash) script parses the alert data into individual variables.
3+
This shell script ([**alerts_variables.sh**](alerts_variables.sh)) parses the alert data into individual variables.
44

5-
This simplifies using any alert fields in the script, which then can be used as `$<field>` (e.g. $runId, $message, $jobName, etc) when calling the command used to send the alerts to an external tool.
5+
It simplifies using any alert fields in the script, which can be then used as `$<field>` (e.g. $runId, $message, $jobName, etc) when calling the command used to send alerts to an external tool.
66

77
As an example, the alert data is saved into a file, but this could be replaced by any other action.
88

9-
## Usage
9+
## Instructions
1010

1111
- If you use the script as it is (saving the alert data into a file), update the **alerts_dir** and **alerts_file** variables with your custom file location.
1212

@@ -20,4 +20,10 @@ The alert data is passed as parameters to the script with the format `<field1>:
2020

2121
As some fields can have an empty value, it is not possible to simply reference the input parameters as $1, $2, $3, etc - as the order may change. This scripts simplifies using each field value in the script, which can be referenced simply as variables with the same field name, as in the the following example:
2222

23-
echo "$time | $id | $severity | $runId | $application | $jobName | $host | $message" >> myfile.txt
23+
echo "$time | $id | $severity | $runId | $application | $jobName | $host | $message" >> myfile.txt
24+
25+
## Versions
26+
27+
| Date | Updated by | Changes |
28+
| - | - | - |
29+
| 2023-02-03 | David Fernández | First release |

helix-control-m/2-external-monitoring-tools-examples/alerts-data-to-json/README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
## Description
22

3-
This Linux (bash) script converts the received alert data to JSON, which can be useful when an external tool is expecting the input data in such format.
3+
This shell script ([**alerts_json.sh**](alerts_json.sh)) converts the alert data to JSON, which can be useful when an external tool is expecting the input in such format.
44

5-
As an example, the alert data is saved into a file, but this could be replaced by any other action (e.g. sending the alert data in JSON via a webhook).
5+
As an example, the alert data is saved into a file, but this could be replaced by any other action (e.g. sending the alert data as a JSON payload via a webhook).
66

7-
## Usage
7+
## Instructions
88

99
- If you use the script as it is (saving the JSON data into a file), update the **alerts_dir** and **alerts_file** variables with your custom file location.
1010

@@ -15,7 +15,7 @@ As an example, the alert data is saved into a file, but this could be replaced b
1515
The alert data is passed as parameters to the script with the format `<field1>: <value1> <field2>: <value2> [...]`, as in the following example:
1616

1717
eventType: I id: 2193 server: IN01 fileName: runId: 00q2e severity: V status: 0 time: 20221126150057 user: updateTime: message: Ended not OK runAs: ctmagent subApplication: application: my-demos jobName: my-sample-job host: zzz-linux-agent-1 type: R closedByControlM: ticketNumber: runNo: 00001 notes:
18-
18+
\
1919
The script parses the input data and converts it to JSON format, starting with the "*alertFields*" key and followed by an array containing all the alert fields and their corresponding values - as in the example below. This is the same JSON structure as the one received when connecting to the External Alerts service via a WebSocket client.
2020

2121
{
@@ -42,4 +42,10 @@ The script parses the input data and converts it to JSON format, starting with t
4242
{"runNo" : "00001"},
4343
{"notes" : ""}
4444
]
45-
}
45+
}
46+
47+
## Versions
48+
49+
| Date | Updated by | Changes |
50+
| - | - | - |
51+
| 2023-02-03 | David Fernández | First release |
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
## Description
2+
3+
This shell script ([**alerts_to_bhom.sh**](alerts_to_bhom.sh)) sends BMC Helix Control-M alerts as events to BMC Helix Operations Management.
4+
5+
It parses the alert data coming from Helix Control-M (**HCTM**) into JSON format, and then sends it to Helix Operations Management (**BHOM**) using its event ingestion API. The JSON data is structured according to an event class which has to be previously created in BHOM.
6+
7+
## Pre-requisites
8+
9+
- **Configure the HCTM "External Alert Management" service** from the Automation API to execute the script every time an alert is raised.
10+
11+
- For more information, check the HCTM documentation for [Setting Up External Alerts](https://documents.bmc.com/supportu/controlm-saas/en-US/Documentation/Alerts.htm#SettingUpExternalAlerts) and the HCTM Automation API documentation for [External Alert Management](https://docs.bmc.com/docs/saas-api/run-service-941879047.html#Runservice-alert_managementExternalAlertManagement).
12+
13+
- As explained in the documentation, you need to use "run alerts:listener:script::set" to define the path to the script - and then open the alerts stream and start the alerts listener process.
14+
15+
- **Create a new Event Class in BHOM**, using the definition from the [**bhom_ctm_event_class.json**](bhom_ctm_event_class.json) file.
16+
17+
This event class called "**ControlMAlert**" includes all the required fields from the HCTM alert data, plus one additional field to include a link to the job that generated the alert (when applicable). It also inherits all fields from its parent classes "IIMonitorEvent", "MonitorEvent" and the "Event" base class (check the BHOM documentation on [Event classification and formatting](https://docs.bmc.com/docs/helixoperationsmanagement/231/event-classification-and-formatting-1160751038.html) for more details).
18+
19+
- To create the event class, contact your BHOM administrator or follow the documentation for [Event management endpoints in the REST API](https://docs.bmc.com/docs/helixoperationsmanagement/231/event-management-endpoints-in-the-rest-api-1160751462.html) (*remember to select your product version*), and use the "POST /events/classes" endpoint.
20+
21+
- If the "IIMonitorEvent" event class is not available in your BHOM environment, you can update the json file to use the "MonitorEvent" class instead.
22+
23+
- **Import an Event Policy in BHOM**, using the [**bhom_ctm_event_policy.json**](bhom_ctm_event_policy.json) file. **[OPTIONAL]**
24+
25+
This event policy can be useful when alerts are also managed from HCTM (e.g. when an operator uses the HCTM web interface to close an alert, modify the urgency or add a comment), and we want to automatically reflect those changes in BHOM. If the HCTM alerts are only going to be managed from BHOM, there is no need to import this event policy.
26+
27+
Depending on the case, remember to set the "**alert_updates**" variable in the script accordingly (Y/N). If set to "N", alert updates are not sent to BHOM (and the policy will never apply, even if imported). If set to "Y", it is recommended to use the policy to avoid creating duplicate events in BHOM every time the alert details are updated from HCTM.
28+
29+
The event policy will automatically 1) update existing events coming from HCTM if they already exist in BHOM (which happens when the alert "Status", "Urgency" or "Comment" are updated in HCTM), 2) map the status from the HCTM alert to the BHOM event (e.g. close the event in BHOM if the alert is closed in HCTM), and 3) record the last alert comment into the BHOM notes history. Be aware that, if the event is closed in BHOM and the associated alert is updated from HCTM, a new event (with the same "alertId") will be created.
30+
31+
- To import the event policy from the BHOM console, go to the "Configuration" menu and select "Event Policies", click on the import button (located on the top right corner, right to the "Create" button) and attach the json file. Once imported, remember to select the policy name and click on the "Enable" button.
32+
33+
- To import the event policy using the API, follow the BHOM documentation for [Event policy management endpoints in the REST API](https://docs.bmc.com/docs/helixoperationsmanagement/231/event-policy-management-endpoints-in-the-rest-api-1160751484.html), and use the "POST /event_policies" endpoint.
34+
35+
## Instructions
36+
37+
Before using the script, update the following variables:
38+
39+
- **hctm_url** : enter the URL for the HCTM tenant (e.g. "*https://\<tenant name\>.us1.controlm.com*").
40+
- **hctm_name** : the default is "Helix Control-M", but can be updated to e.g. use different names for multiple HCTM environments (the value is assigned to the BHOM "location" field).
41+
- **bhom_url** : enter the URL for the BHOM event data endpoint (e.g. "*https://\<BMC Helix Portal URL\>/events-service/api/v1.0/events*"), as described in the BHOM documentation for [Policy, event data, and metric data management endpoints in the REST API](https://docs.bmc.com/docs/helixoperationsmanagement/231/policy-event-data-and-metric-data-management-endpoints-in-the-rest-api-1160751457.html).
42+
- **bhom_api_key** : enter a valid BHOM API key, which you can obtain from the BHOM console in the "Administration" menu, selecting "Repository" and clicking on "Copy API Key".
43+
- **sev_V/U/R** : update the three variables to set the HCTM to BHOM correspondence for the "severity" field according to your preferences (alerts coming from HCTM can be Very urgent, Urgent or Regular; while BHOM event severity can be CRITICAL, MAJOR, MINOR, WARNING, INFO, OK or UNKNOWN).
44+
- **alert_updates** : select whether you want to send or not updates of existing HCTM alerts to BHOM (which happens when the alert "Status", "Urgency" or "Comment" are updated in HCTM).
45+
46+
Do NOT modify the following variables:
47+
48+
- **bhom_class** : leave as is to use the previously imported "ControlMAlert" event class.
49+
- **alert_fields** : leave as is to use the default field names for HCTM alerts. If you have previously modified the JSON template for alerts in HCTM, restore the default alert fields (as documented in the [Alerts Template reference](https://docs.bmc.com/docs/saas-api/alerts-template-reference-1144242602.html)).
50+
- **bhom_slots** : leave as is to use the default event slots defined in the "ControlMAlert" class.
51+
52+
## Additional information
53+
54+
- The integration has been tested with:
55+
56+
- BMC Helix Control-M 9.0.21.080
57+
- BMC Helix Operations Management 23.1
58+
59+
- You can create an **Event Group** in BHOM to show HCTM alerts only:
60+
61+
- In the BHOM console, go to the "Configuration" menu, select "Groups" and click on "Create".
62+
- In the "Group Information" section, enter the group name (e.g. "Helix Control-M") and a description.
63+
- In the "Selection Query" section, go to "Event Selection Criteria" and add "Class Equals ControlMAlert".
64+
- Save the Group. Now you can go to the "Monitoring" menu, select "Groups" and click on the one you just created to view only events related to HCTM.
65+
66+
- You can create a custom **Table View** in BHOM to show any HCTM alert fields of your choice in the "Events" or "Groups" dashboards.
67+
68+
- Follow the steps in the BHOM documentation for [Creating table views](https://docs.bmc.com/docs/helixoperationsmanagement/231/creating-table-views-1160750840.html).
69+
- For example, a custom table view can be used to show the "jobLink" field in the main event dashboard, which when clicked will open the HCTM web interface with a monitoring viewpoint showing the problematic job and its neighborhood (when the alert is related to a job, and as long as the user is already logged in the HCTM web interface).
70+
71+
- If you get the error "*curl: (48) An unknown option was passed in to libcurl*" when testing the script, uncomment the following line:
72+
73+
``export LD_LIBRARY_PATH="/usr/lib64:$LD_LIBRARY_PATH"``
74+
75+
- The following table shows the correspondence between the HCTM alert fields and the BHOM event slots (defined in the "ControlMAlert" class or inherited from its parent classes), plus additional information for fields which are modified in the script.
76+
77+
For more information on the HCTM alert fields, check the [Alerts Template reference](https://docs.bmc.com/docs/saas-api/alerts-template-reference-1144242602.html) documentation.
78+
79+
| HCTM alert field | BHOM event slot | Comments |
80+
| - | - | - |
81+
| ``eventType`` | ``eventType`` | |
82+
| ``id`` | ``alertId`` | |
83+
| ``server`` | ``ctmServer`` | |
84+
| ``fileName`` | ``fileName`` | |
85+
| ``runId`` | ``runId`` | |
86+
| ``severity`` | ``severity`` | The value is updated to map the HCTM to BHOM correspondence. Not included in the "ControlMAlert" class, as it is inherited from the base class "Event". |
87+
| ``status`` | ``alertStatus`` | |
88+
| ``time`` | ``creation_time`` | The value is converted to the format expected by BHOM (Epoch time, in milliseconds). Not included in the "ControlMAlert" class, as it is inherited from the base class "Event". |
89+
| ``user`` | ``ctmUser`` | |
90+
| ``updateTime`` | ``updateTime`` | The value is converted to the format expected by BHOM (Epoch time, in milliseconds). |
91+
| ``message`` | ``msg`` | Not included in the "ControlMAlert" class, as it is inherited from the base class "Event". |
92+
| ``runAs`` | ``runAs`` | |
93+
| ``subApplication`` | ``subApplication`` | |
94+
| ``application`` | ``application`` | |
95+
| ``jobName`` | ``jobName`` | |
96+
| ``host`` | ``source_hostname`` | When the alert "host" value is empty, it defaults to the "source_identifier" event slot. Not included in the "ControlMAlert" class, as it is inherited from the base class "Event". |
97+
| ``type`` | ``alertType`` | |
98+
| ``closedByControlM`` | ``closedByControlM`` | |
99+
| ``ticketNumber`` | ``ticketNumber`` | |
100+
| ``runNo`` | ``runNo`` | |
101+
| ``notes`` | ``alertNotes`` | |
102+
| | ``jobLink`` | Additional slot included in the "ControlMAlert" class, which value is defined in the script using the HCTM tenant URL, runId, ctmServer and jobName. |
103+
| | ``location`` | The value is defined in the script using the "hctm_name" variable. Not included in the "ControlMAlert" class, as it is inherited from the base class "Event". |
104+
| | ``source_identifier`` | The value is defined in the script using the HCTM tenant URL (removing the "https://"). Not included in the "ControlMAlert" class, as it is inherited from the base class "Event". |
105+
106+
- The script could be modified to also include the ``external_id`` slot from the "IIMonitorEvent" class, in order to associate the event with a CI (configuration item).*
107+
108+
## Versions
109+
110+
| Date | Updated by | Changes |
111+
| - | - | - |
112+
| 2023-03-18 | David Fernández | First release |
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/bin/bash
2+
#
3+
# Sends BMC Helix Control-M (HCTM) alerts as events to BMC Helix Operations Management (BHOM)
4+
#
5+
# Notes : - The alert data is sent in JSON format to BHOM using its event ingestion API
6+
# - The "ControlMAlert" event class must be previously imported in BHOM
7+
# - Update variables below according to your environment and preferences
8+
#
9+
10+
# Set HCTM parameters
11+
hctm_url=https://my-hctm-tenant.us1.controlm.com
12+
hctm_name="Helix Control-M"
13+
14+
# Set BHOM parameters
15+
bhom_url=https://my-bmc-helix-portal.com/events-service/api/v1.0/events
16+
bhom_api_key=mybh0m12-1234-1234-1234-ap1k3y123456
17+
bhom_class="ControlMAlert"
18+
19+
# Set HCTM to BHOM correspondence for the "severity" field
20+
# HCTM : V (Very urgent), U (Urgent), R (Regular) | BHOM : CRITICAL, MAJOR, MINOR, WARNING, INFO, OK, UNKNOWN
21+
sev_V="CRITICAL"
22+
sev_U="MAJOR"
23+
sev_R="MINOR"
24+
25+
# Send updates of existing alerts? (Y/N)
26+
alert_updates="Y"
27+
28+
# Declare arrays with the HCTM alert fields and BHOM slot names - DO NOT MODIFY
29+
alert_fields=("eventType" "id" "server" "fileName" "runId" "severity" "status" "time" "user" "updateTime" "message" "runAs" "subApplication" "application" "jobName" "host" "type" "closedByControlM" "ticketNumber" "runNo" "notes")
30+
bhom_slots=("eventType" "alertId" "ctmServer" "fileName" "runId" "severity" "alertStatus" "creation_time" "ctmUser" "updateTime" "msg" "runAs" "subApplication" "application" "jobName" "source_hostname" "alertType" "closedByControlM" "ticketNumber" "runNo" "alertNotes")
31+
32+
# If alert updates are not needed, exit if "call_type" = "U"
33+
if [ $alert_updates == "N" ] ; then
34+
if [ $2 == "U" ] ; then exit 0 ; fi
35+
fi
36+
37+
# Start JSON and add first BHOM slots
38+
hctm_tenant=`echo $hctm_url | cut -c 9-`
39+
json_data="[ { \"class\" : \"$bhom_class\", \"location\" : \"$hctm_name\", \"source_identifier\" : \"$hctm_tenant\""
40+
41+
# Start creating url for the job link
42+
job_link=$hctm_url/ControlM/#Neighborhood:
43+
44+
# START PROCESSING ALERT DATA
45+
num_fields=${#alert_fields[@]}
46+
for (( i=0; i<=$((num_fields-1)); i++ )) ; do
47+
field=${alert_fields[$i]}
48+
next_field=${alert_fields[$i+1]}
49+
if [ $i != $((num_fields-1)) ] ; then
50+
value=`echo $* | grep -oP "(?<=\b${field}\b: ).*?(?= \b${next_field}\b:)"`
51+
52+
# Update some fields for BHOM compatibility
53+
case $field in
54+
server)
55+
# Save "server" value in a variable (for the job link)
56+
ctm_server=$value
57+
;;
58+
runId)
59+
# Add "runId" and "server" to the job link
60+
job_link=$job_link"id="$value"&ctm="$ctm_server
61+
;;
62+
severity)
63+
# Convert "severity" format from HCTM to BHOM
64+
bhom_severity="sev_${value}"
65+
value=${!bhom_severity}
66+
;;
67+
time | updateTime)
68+
# Convert to Epoch time, in milisecs
69+
D="$value"
70+
value=`date -d "${D:0:8} ${D:8:2}:${D:10:2}:${D:12:2} +0000" "+%s%3N"`
71+
;;
72+
jobName)
73+
# Add "jobName" to the final job link
74+
job_name="${value// /%20}" # Replace spaces by "%20"
75+
job_link=$job_link"&name="$job_name"&direction=1&radius=3" # Direction and radius can be customized
76+
;;
77+
host)
78+
# Save "host" value in a variable (used to determine whether to include the job link)
79+
saved_host=$value
80+
;;
81+
esac
82+
83+
else
84+
# If last field, capture until EOL
85+
value=`echo $* | grep -oP "(?<=\b${field}\b: ).*"`
86+
fi
87+
slot_name=${bhom_slots[$i]}
88+
text=", \"$slot_name\" : \"$value\""
89+
json_data=$json_data$text
90+
done
91+
92+
# Add link to the problematic job (only if "host" was not empty, meaning it is an alert related to a job)
93+
if [ ! -z "$saved_host" ] ; then
94+
json_data=$json_data", \"jobLink\" : \"$job_link\""
95+
fi
96+
97+
# Close JSON
98+
json_data=$json_data" } ]"
99+
100+
# Set library path to solve curl error when Helix Control-M Agent is installed
101+
# USE ONLY if you get the error: "curl: (48) An unknown option was passed in to libcurl"
102+
# See https://bmcsites.force.com/casemgmt/sc_KnowledgeArticle?sfdcid=kA33n000000YHinCAG&type=Solution
103+
# export LD_LIBRARY_PATH="/usr/lib64:$LD_LIBRARY_PATH"
104+
105+
# Send HCTM alert data to BHOM
106+
curl -X POST $bhom_url -H "Authorization: apiKey $bhom_api_key" -H 'Content-Type: application/json' -d "$json_data"
107+
108+
exit 0

0 commit comments

Comments
 (0)