brpm_module_demo 0.1.16 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODI2YWVlY2VlYmIxMzk3YmIwNjMwOTQwNTIxYmM2ZjA0ODg3MDIzZg==
4
+ MWE3NzIxY2U2MTE0ODJiYjZhZmVmYTVmM2VlODUwODFjYzhmOGE0ZQ==
5
5
  data.tar.gz: !binary |-
6
- MDQyYThjNzkwZGRjODRmZTdmNDRkZmNlOWU1MjMyN2MyODFmZWEyZg==
6
+ OGY1MGYxNjI2Yjk4ZjQ1ZjQ2NDI1OWM4M2ExMjg4MDU2MWQ4OTZkMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTdmZWJjNGM3M2VmYmQ2MjA4ZjhjN2IzNGZhNjczMjY1MWIyZDJiMmQ2ODgx
10
- NDQ2MDM4YTI4OGFhNDg1ZmEwZThjY2RiNWUwMjNjNWQ4MGMzMzJkMjVkZjYw
11
- ZjE3YTMzODJkNGI3ZjllOGNkY2U5MTI3YzNjZjU2Mjg0MmI1MzU=
9
+ ZmYxNmYzYmMxNjEzYzdhZmY4MTRlYmZlYzJiOTUwOTNmY2IxYjJjOTRmMTBj
10
+ MWQ3MTE3ZjE0YTYxM2Q4ZDE4NzY5OTcwZTY3ZTdkZTlmMDI0OGVjOTM4OTRj
11
+ ODIxNjhhNjI3ZDM0NTVjNTJmNjA5NjE4NmI3ZjgyZDM3YjM4NGM=
12
12
  data.tar.gz: !binary |-
13
- MTJhMzQwZmI5MWFhMzM0ZGNhNWVmM2I1OWExOGEzMGU0MGFhNTlmY2FiOGY0
14
- M2YwMDVhMWU2ZGI1MjU4Y2U2NmQ3NTIyOGQ4MDdmODg4MGNlOWIzNzcwZDIz
15
- YjNhNThlMjczNGZmYTIxOWE3NjdkODIxZDg2YmM2MTY5MjUxYzQ=
13
+ ZjZkOWFkN2Q4ZmNiMzM2Y2E0MDdkZTU2MjU5NzRjNjNmYTMzMGY4M2M4NWI1
14
+ YmUzNTIwNTA0MmE5YmQ1NzkyNTk2MTVkOTA3MDE4MzBiZjAyZjg4YzVkMmY3
15
+ ZGY5ZTNlMjRlYTNjNzY2ZDE0NDIwZDg3ODVmYTA3MDdiNDA4ZmI=
data/README.md CHANGED
@@ -4,4 +4,4 @@
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/brpm_module_demo.png)](http://badge.fury.io/rb/brpm_module_demo)
6
6
 
7
- This repository represents an module for a fictive customer "Demo", to be used on top of the [BRPM content framework](https://github.com/BMC-RLM/brpm_content_framework). It contains customer-specific logic to integrate BRPM and JIRA in both directions: creating BRPM tickets from created or updated JIRA issues and udating the state of JIRA issues after a request was deployed into an environment.
7
+ This repository represents an module for a fictive customer "Demo", to be used on top of the [BRPM content framework](https://github.com/BMC-RLM/brpm_content_framework). It contains customer-specific logic to integrate JIRA, Jenkins and ServiceNow to BRPM.
data/config.yml CHANGED
@@ -1,8 +1,9 @@
1
1
  dependencies:
2
2
  - brpm_module_brpm
3
3
  - brpm_module_jira
4
+ - brpm_module_servicenow
4
5
 
5
- version: 0.1.16
6
+ version: 0.1.17
6
7
 
7
8
  author: Niek Bartholomeus
8
9
  email: niek.bartholomeus@gmail.com
@@ -4,7 +4,10 @@ require_relative "../../jira_mappings"
4
4
  def process_event(event)
5
5
  @brpm_rest_client = BrpmRestClient.new("http://#{ENV["EVENT_HANDLER_BRPM_HOST"]}:#{ENV["EVENT_HANDLER_BRPM_PORT"]}/brpm", ENV["EVENT_HANDLER_BRPM_TOKEN"])
6
6
 
7
- if event.has_key?("request")
7
+ if event.has_key?("step")
8
+ BrpmAuto.log "The event is for a step #{event["event"][0]}..."
9
+ process_step_event(event)
10
+ elsif event.has_key?("request")
8
11
  BrpmAuto.log "The event is for a request #{event["event"][0]}..."
9
12
  process_request_event(event)
10
13
  elsif event.has_key?("run")
@@ -16,11 +19,36 @@ def process_event(event)
16
19
  end
17
20
  end
18
21
 
22
+ def process_step_event(event)
23
+ if event["event"][0] == "create"
24
+ step = event["step"].find { |item| item["type"] == "new" }
25
+
26
+ BrpmAuto.log "Step '#{step["name"][0]}' created"
27
+ elsif event["event"][0] == "update"
28
+ step_old_state = event["step"].find { |item| item["type"] == "old" }
29
+ step_new_state = event["step"].find { |item| item["type"] == "new" }
30
+
31
+ if step_old_state["aasm-state"][0] != step_new_state["aasm-state"][0] or step_new_state["aasm-state"][0] == "complete" #TODO bug when a request is moved to complete the old state is also reported as complete
32
+ BrpmAuto.log "Step '#{step_new_state["name"][0]}' moved from state '#{step_old_state["aasm-state"][0]}' to state '#{step_new_state["aasm-state"][0]}'"
33
+
34
+ if step_new_state["aasm-state"][0] == "complete" or step_new_state["aasm-state"][0] == "problem"
35
+ if step_new_state["property-values"][0].has_key?("add-logs-to-request-params") and step_new_state["property-values"][0]["add-logs-to-request-params"] == "true"
36
+ add_logs_to_ticket_in_servicenow(step_new_state)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
19
43
  def process_request_event(event)
20
44
  if event["event"][0] == "create"
21
45
  request = event["request"].find { |item| item["type"] == "new" }
22
46
 
23
47
  BrpmAuto.log "Request '#{request["name"][0]}' created"
48
+
49
+ if request["wiki-url"][0] == "ServiceNow change request"
50
+ add_link_to_ticket_in_servicenow(request)
51
+ end
24
52
  elsif event["event"][0] == "update"
25
53
  request_old_state = event["request"].find { |item| item["type"] == "old" }
26
54
  request_new_state = event["request"].find { |item| item["type"] == "new" }
@@ -86,9 +114,19 @@ def process_plan_event(event)
86
114
  end
87
115
  end
88
116
 
117
+
89
118
  #################################
90
119
  # BRPM
91
120
 
121
+ def get_default_params
122
+ params = {}
123
+ params["brpm_url"] = "http://#{ENV["EVENT_HANDLER_BRPM_HOST"]}:#{ENV["EVENT_HANDLER_BRPM_PORT"]}/brpm"
124
+ params["brpm_api_token"] = ENV["EVENT_HANDLER_BRPM_TOKEN"]
125
+
126
+ params["log_file"] = ENV["EVENT_HANDLER_LOG_FILE"]
127
+ params
128
+ end
129
+
92
130
  def process_app_release_event(request)
93
131
  release_request_stage_name = "Release"
94
132
  release_request_environment_name = "development"
@@ -116,21 +154,17 @@ end
116
154
  #################################
117
155
  # JIRA
118
156
 
119
- def get_default_params
120
- params = {}
157
+ def get_default_params_for_jira
158
+ params = get_default_params
121
159
  params["SS_integration_dns"] = ENV["EVENT_HANDLER_JIRA_URL"]
122
160
  params["SS_integration_username"] = ENV["EVENT_HANDLER_JIRA_USERNAME"]
123
161
  params["SS_integration_password"] = ENV["EVENT_HANDLER_JIRA_PASSWORD"]
124
162
 
125
- params["brpm_url"] = "http://#{ENV["EVENT_HANDLER_BRPM_HOST"]}:#{ENV["EVENT_HANDLER_BRPM_PORT"]}/brpm"
126
- params["brpm_api_token"] = ENV["EVENT_HANDLER_BRPM_TOKEN"]
127
-
128
- params["log_file"] = ENV["EVENT_HANDLER_LOG_FILE"]
129
163
  params
130
164
  end
131
165
 
132
166
  def update_tickets_in_jira_by_request(request)
133
- params = get_default_params
167
+ params = get_default_params_for_jira
134
168
  params["request_id"] = (request["id"][0]["content"].to_i + 1000).to_s
135
169
 
136
170
  request_with_details = @brpm_rest_client.get_request_by_id(request["id"][0]["content"])
@@ -145,7 +179,7 @@ def update_tickets_in_jira_by_request(request)
145
179
  end
146
180
 
147
181
  def update_tickets_in_jira_by_run(run)
148
- params = get_default_params
182
+ params = get_default_params_for_jira
149
183
  params["run_id"] = run["id"][0]["content"]
150
184
 
151
185
  BrpmAuto.log "Getting the stage of this run..."
@@ -158,7 +192,7 @@ def update_tickets_in_jira_by_run(run)
158
192
  end
159
193
 
160
194
  def create_release_in_jira(plan)
161
- params = get_default_params
195
+ params = get_default_params_for_jira
162
196
  params["jira_release_field_id"] = ENV["EVENT_HANDLER_JIRA_RELEASE_FIELD_ID"]
163
197
  params["release_name"] = plan["name"][0]
164
198
 
@@ -166,7 +200,7 @@ def create_release_in_jira(plan)
166
200
  end
167
201
 
168
202
  def update_release_in_jira(old_plan, new_plan)
169
- params = get_default_params
203
+ params = get_default_params_for_jira
170
204
  params["jira_release_field_id"] = ENV["EVENT_HANDLER_JIRA_RELEASE_FIELD_ID"]
171
205
  params["old_release_name"] = old_plan["name"][0]
172
206
  params["new_release_name"] = new_plan["name"][0]
@@ -175,10 +209,49 @@ def update_release_in_jira(old_plan, new_plan)
175
209
  end
176
210
 
177
211
  def delete_release_in_jira(plan)
178
- params = get_default_params
212
+ params = get_default_params_for_jira
179
213
  params["jira_release_field_id"] = ENV["EVENT_HANDLER_JIRA_RELEASE_FIELD_ID"]
180
214
  params["release_name"] = plan["name"][0]
181
215
 
182
216
  BrpmScriptExecutor.execute_automation_script("brpm_module_jira", "delete_release", params)
183
217
  end
184
218
  #################################
219
+
220
+ #################################
221
+ # ServiceNow
222
+
223
+ def get_default_params_for_servicenow
224
+ params = get_default_params
225
+ params["SS_integration_dns"] = ENV["EVENT_HANDLER_SERVICENOW_URL"]
226
+ params["SS_integration_username"] = ENV["EVENT_HANDLER_SERVICENOW_USERNAME"]
227
+ params["SS_integration_password"] = ENV["EVENT_HANDLER_SERVICENOW_PASSWORD"]
228
+
229
+ params
230
+ end
231
+
232
+ def add_link_to_ticket_in_servicenow(request)
233
+ request_with_details = @brpm_rest_client.get_request_by_id(request["id"][0]["content"])
234
+
235
+ request_params = RequestParams.new_for_request("#{ENV["BRPM_HOME"]}/automation_results", request_with_details["apps"][0]["name"], request_with_details["id"].to_i + 1000)
236
+
237
+ params = get_default_params_for_servicenow
238
+ params["change_request_id"] = request_params["change_request_id"]
239
+
240
+ params["fields"] = { "u_url_brpm_request" => "#{params["brpm_url"]}/requests/#{request_with_details["id"]}" }
241
+
242
+ BrpmScriptExecutor.execute_automation_script("brpm_module_servicenow", "update_change_request", params)
243
+ end
244
+
245
+ def add_logs_to_ticket_in_servicenow(step)
246
+ step_with_details = @brpm_rest_client.get_step_by_id(step["id"][0]["content"])
247
+
248
+ request_params = RequestParams.new_for_request("#{ENV["BRPM_HOME"]}/automation_results", step_with_details["installed_component"]["app"]["name"], step["request"]["id"].to_i + 1000)
249
+
250
+ params = get_default_params_for_servicenow
251
+ params["change_request_id"] = request_params["change_request_id"]
252
+
253
+ params["fields"] = { "u_string_brpm_log_note" => request_params["logs"].map { |k, v| "#{k}:\n#{v}"} }
254
+
255
+ BrpmScriptExecutor.execute_automation_script("brpm_module_servicenow", "update_change_request", params)
256
+ end
257
+ #################################
@@ -0,0 +1,25 @@
1
+ # JIRA to BRPM integration
2
+ ## Intro
3
+ This integration will automatically synchronize JIRA issues with BRPM tickets when an issue is created, updated or deleted in JIRA. This is just a first step in integrating JIRA with BRPM. It can easily be extended to cover more complex integration needs. Integrations from BRPM to JIRA can be found in the [JIRA module](https://github.com/BMC-RLM/brpm_module_jira).
4
+
5
+ ## Getting started
6
+ The integration is done with webhooks: we will set up a tiny HTTP server that listens on a certain mount point (in this case "webhooks") and have JIRA send its notifications as POSTs to this server. The process_webhook_events.rb script will then take action based on the contents of the notifications.
7
+
8
+ ### Running the webhook receiver
9
+ The ```process_webhook_event.rb``` script should be used with a [webhook_receiver](https://github.com/BMC-RLM/brpm_content_framework/blob/master/bin/webhook_receiver). The easiest way to set this up is with a wrapper script like ```run_jira_webhook_receiver.sh``` that sets the necessary environment variables. Copy it to a location of your choice and adapt the environment variables where needed.
10
+
11
+ Execute the wrapper script in daemon mode: ```nohup /path/to/run_jira_webhook_receiver.sh &```
12
+
13
+ ### Mapping the fields
14
+ The mapping between an issue in JIRA and a ticket in BRPM can be configured in the [jira_mappings.rb](https://github.com/BMC-RLM/brpm_module_demo/blob/master/lib/jira_mappings.rb) script. Make sure to restart the webhook receiver after each change to this script.
15
+
16
+ ### Configuring the webhook in JIRA
17
+ - First of all make sure that your projects in JIRA have exactly the same name as your applications in BRPM.
18
+
19
+ - Create a WebHook (in System > Advanced > WebHooks) and set the url to http://your-server:port/webhooks. You can tweak the other fields to your specific needs as it's all quite self-explanatory, just make sure to "include the details" of the issues.
20
+
21
+ ### Creating an issue in JIRA
22
+ Voila, we're all set. Now create a change request in ServiceNow and see how it triggers a request in BRPM!
23
+
24
+
25
+
@@ -0,0 +1,15 @@
1
+ #!/bin/bash
2
+ # mandatory settings
3
+ export WEBHOOK_RECEIVER_PORT=8089
4
+ export WEBHOOK_RECEIVER_MOUNT_POINT=webhooks
5
+ export WEBHOOK_RECEIVER_LOG_FILE=/tmp/webhook_receiver.log
6
+ export WEBHOOK_RECEIVER_PROCESS_EVENT_SCRIPT=integrations/jira/process_webhook_event.rb
7
+
8
+ # custom settings
9
+ export WEBHOOK_RECEIVER_BRPM_HOST=localhost
10
+ export WEBHOOK_RECEIVER_BRPM_PORT=8088
11
+ export WEBHOOK_RECEIVER_BRPM_TOKEN=???
12
+ export WEBHOOK_RECEIVER_INTEGRATION_ID=<the id of the JIRA integration in BRPM>
13
+ export WEBHOOK_RECEIVER_JIRA_RELEASE_FIELD_ID=<the id of a custom dropdown field in JIRA that contains the release plans>
14
+
15
+ webhook_receiver
@@ -1,16 +1,20 @@
1
- # Service-Now to BRPM integration
1
+ # ServiceNow to BRPM integration
2
2
  ## Intro
3
- This integration will automatically create a request in BRPM when a new change request is created in Service-Now. This is just a first step in integration Service-Now with BRPM. It can easily be extended to cover more complex integration needs.
3
+ This integration will automatically create a request in BRPM when a change request is created in ServiceNow. This is just a first step in integrating ServiceNow with BRPM. It can easily be extended to cover more complex integration needs. Integrations from BRPM to ServiceNow can be found in the [ServiceNow module](https://github.com/BMC-RLM/brpm_module_servicenow).
4
4
 
5
5
  ## Getting started
6
- ### Running the webhook receiver as a daemon
7
- This script should be used with a [webhook_receiver wrapper](https://github.com/BMC-RLM/brpm_content_framework/blob/master/infrastructure/scripts/run_webhook_receiver.sh). Set the environment variable ```WEBHOOK_RECEIVER_PROCESS_EVENT_SCRIPT``` to the location of this script and execute it in daemon mode: ```nohup ./run_webhook_receiver.sh &```
6
+ The integration is done with webhooks: we will set up a tiny HTTP server that listens on a certain mount point (in this case "webhooks") and have ServiceNow send its notifications as POSTs to this server. The process_webhook_events.rb script will then take action based on the contents of the notifications.
7
+
8
+ ### Running the webhook receiver
9
+ The ```process_webhook_event.rb``` script should be used with a [webhook_receiver](https://github.com/BMC-RLM/brpm_content_framework/blob/master/bin/webhook_receiver). The easiest way to set this up is with a wrapper script like ```run_servicenow_webhook_receiver.sh``` that sets the necessary environment variables. Copy it to a location of your choice and adapt the environment variables where needed.
10
+
11
+ Execute the wrapper script in daemon mode: ```nohup /path/to/run_servicenow_webhook_receiver.sh &```
8
12
 
9
13
  ### Creating a request template in BRPM
10
14
  Create one or more request templates with the name ```[Template] Self Service - <automation type>``` where automation_type can be "Reboot server", etc.
11
15
 
12
- ### Configuring Service-Now
13
- - Create a new dropdown field for a change request with the name u_choice_automation_type and configure a nmber of choices like "Reboot server" etc.
16
+ ### Configuring ServiceNow
17
+ - Create a new dropdown field for a change request with the name u_choice_automation_type and configure a number of choices like "Reboot server" etc.
14
18
 
15
19
  - Create an outbound REST Message and set the endpoint to http://your-server:port/webhooks (only the POST HTTP method is needed so you may delete the others)
16
20
 
@@ -18,7 +22,7 @@ Create one or more request templates with the name ```[Template] Self Service -
18
22
 
19
23
  You can use this content as an example:
20
24
  ```
21
- {"change_request": {"number":"${number}", "automation_type":"${automation_type}", "cmdb_ci":"${cmdb_ci}"}}
25
+ {"change_request": {"id":"${id}", "number":"${number}", "automation_type":"${automation_type}", "cmdb_ci":"${cmdb_ci}"}}
22
26
  ```
23
27
 
24
28
  - Copy the generated javascript code from the "Preview Script Usage" link
@@ -32,9 +36,10 @@ As an example of a javascript piece of code:
32
36
  function onAfter(current, previous) {
33
37
  try {
34
38
  var r = new sn_ws.RESTMessageV2('BRPM', 'post');
39
+ r.setStringParameter('id', current.sys_id);
35
40
  r.setStringParameter('number', current.number);
36
41
  r.setStringParameter('automation_type', current.u_choice_automation_type);
37
- r.setStringParameter('cmdb_ci', current.cmdb_ci);
42
+ r.setStringParameter('cmdb_ci', current.cmdb_ci.getDisplayValue());
38
43
  var response = r.execute();
39
44
  var responseBody = response.getBody();
40
45
  var httpStatus = response.getStatusCode();
@@ -45,8 +50,8 @@ function onAfter(current, previous) {
45
50
  }
46
51
  ```
47
52
 
48
- ### Creating a change request
49
- Voila, we're all set. Now create a change request in Service-Now and see how it triggers a request in BRPM!
53
+ ### Creating a change request in ServiceNow
54
+ Voila, we're all set. Now create a change request in ServiceNow and see how it triggers a request in BRPM!
50
55
 
51
56
 
52
57
 
@@ -0,0 +1,14 @@
1
+ #!/bin/bash
2
+ # mandatory settings
3
+ export WEBHOOK_RECEIVER_PORT=8089
4
+ export WEBHOOK_RECEIVER_MOUNT_POINT=webhooks
5
+ export WEBHOOK_RECEIVER_LOG_FILE=/tmp/webhook_receiver.log
6
+ export WEBHOOK_RECEIVER_PROCESS_EVENT_SCRIPT=integrations/servicenow/process_webhook_event.rb
7
+
8
+ # custom settings
9
+ export WEBHOOK_RECEIVER_BRPM_HOST=localhost
10
+ export WEBHOOK_RECEIVER_BRPM_PORT=8088
11
+ export WEBHOOK_RECEIVER_BRPM_TOKEN=???
12
+ export WEBHOOK_RECEIVER_INTEGRATION_ID=<the id of the ServiceNow integration in BRPM>
13
+
14
+ webhook_receiver
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brpm_module_demo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niek Bartholomeus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-25 00:00:00.000000000 Z
11
+ date: 2015-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: brpm_content_framework
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: brpm_module_servicenow
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -101,9 +115,12 @@ files:
101
115
  - lib/integrations/jenkins/spec/api/plans_spec.rb
102
116
  - lib/integrations/jenkins/spec/api/requests_spec.rb
103
117
  - lib/integrations/jenkins/spec/spec_helper.rb
118
+ - lib/integrations/jira/README.md
104
119
  - lib/integrations/jira/process_webhook_event.rb
120
+ - lib/integrations/jira/run_jira_webhook_receiver.sh
105
121
  - lib/integrations/servicenow/README.md
106
122
  - lib/integrations/servicenow/process_webhook_event.rb
123
+ - lib/integrations/servicenow/run_servicenow_webhook_receiver.sh
107
124
  - lib/jira_mappings.rb
108
125
  - module.gemspec
109
126
  - tests/gemspec_spec.rb