diff --git a/CHANGES.md b/CHANGES.md index fcfc7b7..3b93e49 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Change Log +## 0.5.0 + +- Convert mistral workflows to orquesta + ## 0.4.1 - Restrict napalm dependency to < 3.0 to preserve Python 2.7 support diff --git a/README.md b/README.md index 7f6a511..5941063 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ credentials: The devices configuration is so that credentials and drivers for each device don't have to be entered manually. This is useful for automated action chains -or mistral workflows where (most of the time) only the hostname is known +or orquesta workflows where (most of the time) only the hostname is known (for example from a syslog logsource field.) ```YAML @@ -171,7 +171,7 @@ being set to the IP address of the host and the logsoure being set to the hostna received from the box. The example rsyslog configuration example details more on this. -- **configuration_change_workflow**: Webhook trigger to run a remote backup mistral workflow when a configuration change is detected on a device. +- **configuration_change_workflow**: Webhook trigger to run a remote backup orquesta workflow when a configuration change is detected on a device. - **interface_down_chain**: Webhook trigger to run an action chain when an interface goes down. - **bgp_prefix_exceeded_chain**: Webhook trigger to run an action chain when a bgp neighbor exceeds its prefix limit. @@ -189,8 +189,8 @@ st2 key set napalm_actionerror_mailto "stackstorm_errors@example.com" st2 key set napalm_actionerror_mailfrom "stackstorm@example.com" # HTML header and footer files which get read in by some of the workflows to send nice emails. -st2 key set napalm_html_mail_header_file "/opt/stackstorm/packs/napalm/examples/html_header.html" -st2 key set napalm_html_mail_footer_file "/opt/stackstorm/packs/napalm/examples/html_footer.html" +st2 key set napalm_html_mail_header_file "/opt/stackstorm/packs/napalm/examples/html_templates/html_header.html" +st2 key set napalm_html_mail_footer_file "/opt/stackstorm/packs/napalm/examples/html_templates/html_footer.html" ``` For the remote backup action chain the following commands will create the datastore key value pairs needed. diff --git a/actions/configuration_change_workflow.yaml b/actions/configuration_change_workflow.yaml index 1028897..708427c 100644 --- a/actions/configuration_change_workflow.yaml +++ b/actions/configuration_change_workflow.yaml @@ -1,7 +1,7 @@ --- name: "configuration_change_workflow" description: "Workflow to process a configuration change on a device." - runner_type: "mistral-v2" + runner_type: "orquesta" pack: napalm enabled: true entry_point: "workflows/configuration_change_workflow.yaml" diff --git a/actions/interface_down_workflow.yaml b/actions/interface_down_workflow.yaml index c5fa84a..65cea4a 100644 --- a/actions/interface_down_workflow.yaml +++ b/actions/interface_down_workflow.yaml @@ -1,7 +1,7 @@ --- name: "interface_down_workflow" description: "Workflow to process an interface down event on a device." - runner_type: "mistral-v2" + runner_type: "orquesta" pack: napalm enabled: true entry_point: "workflows/interface_down_workflow.yaml" diff --git a/actions/workflows/check_consistency_chatops.yaml b/actions/workflows/check_consistency_chatops.yaml deleted file mode 100644 index 1489a72..0000000 --- a/actions/workflows/check_consistency_chatops.yaml +++ /dev/null @@ -1,71 +0,0 @@ ---- - version: '2.0' - - # TODO(mierdin): Might have to convert this to an actionchain, as per-task notifications is not yet supported in mistral - - - napalm.check_consistency_chatops: - - input: - - hostname - - driver - - type: direct - - task-defaults: - on-error: - - notify_on_error - - tasks: - send_detected_email: - action: core.sendmail - input: - to: "<% st2kv('system.napalm_remotebackup_mailto') %>" - from: "<% st2kv('system.napalm_remotebackup_mailfrom') %>" - # Will work when this is in the code: https://github.com/StackStorm/st2/pull/3177 - #subject: "Stackstorm detected a configuration change on <% $.hostname %> {% if _.username %} by {{ _.username }} {% endif %}." - subject: "Stackstorm detected a configuration change on <% $.hostname %> by <% $.username %>." - content_type: "text/plain" - body: "\r\n\r\nThe following syslog triggered this event: <% $.message %>\r\n\r\n" - on-success: - - backup_device - - backup_device: - action: "core.remote" - wait-before: 60 - input: - cmd: "<% st2kv('system.napalm_remotebackup_cmd') %> <% $.hostname %> <% $.driver %>" - username: "<% st2kv('system.napalm_remotebackup_user') %>" - private_key: "/home/stanley/.ssh/stanley_rsa" - hosts: "<% st2kv('system.napalm_remotebackup_host') %>" - publish: - stdout: <% task(backup_device).result.get(st2kv('system.napalm_remotebackup_host')).stdout %> - stderr: <% task(backup_device).result.get(st2kv('system.napalm_remotebackup_host')).stderr %> - on-success: - - send_complete_email - - send_complete_email: - action: core.sendmail - input: - to: "<% st2kv('system.napalm_remotebackup_mailto') %>" - from: "<% st2kv('system.napalm_remotebackup_mailfrom') %>" - subject: "Stackstorm completed a backup of <% $.hostname %>." - content_type: "text/plain" - body: "\r\nThe following syslog triggered this event: <% $.message %>\r\n\r\n - \r\n<% $.stderr %>\r\n - \r\n<% $.stdout %>\r\n - \r\n\r\n" - - # notify_consistent: - - # notify_inconsistent: - - notify_on_error: - action: core.sendmail - input: - to: "<% st2kv('system.napalm_actionerror_mailto') %>" - from: "<% st2kv('system.napalm_actionerror_mailfrom') %>" - subject: "Stackstorm device backup workflow error" - body: "Something went wrong with the device backup workflow. Check stackstorm for the error. Execution ID <% env().st2_execution_id %>\r\n\r\n" - on-complete: - - fail diff --git a/actions/workflows/configuration_change_workflow.yaml b/actions/workflows/configuration_change_workflow.yaml index 0644bb4..86797d0 100644 --- a/actions/workflows/configuration_change_workflow.yaml +++ b/actions/workflows/configuration_change_workflow.yaml @@ -1,66 +1,70 @@ ---- - version: '2.0' +version: 1.0 - napalm.configuration_change_workflow: +description: Configuration Change Workflow - input: - - hostname - - driver - - message - - username - - type: direct +input: + - hostname + - driver + - message + - username - task-defaults: - on-error: - - notify_on_error +vars: + - stdout: "" + - stderr: "" - tasks: - send_detected_email: - action: core.sendmail - input: - to: "<% st2kv('system.napalm_remotebackup_mailto') %>" - from: "<% st2kv('system.napalm_remotebackup_mailfrom') %>" - # Will work when this is in the code: https://github.com/StackStorm/st2/pull/3177 - #subject: "Stackstorm detected a configuration change on <% $.hostname %> {% if _.username %} by {{ _.username }} {% endif %}." - subject: "Stackstorm detected a configuration change on <% $.hostname %> by <% $.username %>." - content_type: "text/plain" - body: "\r\n\r\nThe following syslog triggered this event: <% $.message %>\r\n\r\n" - on-success: - - backup_device +tasks: + send_detected_email: + action: core.sendmail + input: + to: "{{ st2kv('system.napalm_remotebackup_mailto') }}" + from: "{{ st2kv('system.napalm_remotebackup_mailfrom') }}" + subject: "Stackstorm detected a configuration change on {{ ctx('hostname') }} by {{ ctx('username') }}." + content_type: "text/plain" + body: "\r\n\r\nThe following syslog triggered this event: {{ ctx('message') }}\r\n\r\n" + next: + - when: "{{ succeeded() }}" + do: backup_device + - when: "{{ failed() }}" + do: notify_on_error - backup_device: - action: "core.remote" - wait-before: 60 - input: - cmd: "<% st2kv('system.napalm_remotebackup_cmd') %> <% $.hostname %> <% $.driver %>" - username: "<% st2kv('system.napalm_remotebackup_user') %>" - private_key: "/home/stanley/.ssh/stanley_rsa" - hosts: "<% st2kv('system.napalm_remotebackup_host') %>" + backup_device: + action: "core.remote" + input: + cmd: "{{ st2kv('system.napalm_remotebackup_cmd') }} {{ ctx('hostname') }} {{ ctx('driver') }}" + username: "{{ st2kv('system.napalm_remotebackup_user') }}" + private_key: "/home/stanley/.ssh/stanley_rsa" + hosts: "{{ st2kv('system.napalm_remotebackup_host') }}" + next: + - when: "{{ succeeded() }}" publish: - stdout: <% task(backup_device).result.get(st2kv('system.napalm_remotebackup_host')).stdout %> - stderr: <% task(backup_device).result.get(st2kv('system.napalm_remotebackup_host')).stderr %> - on-success: - - send_complete_email + - stdout: "{{ result()[st2kv('system.napalm_remotebackup_host')].stdout }}" + - sterr: "{{ result()[st2kv('system.napalm_remotebackup_host')].stdout }}" + do: send_complete_email + - when: "{{ failed() }}" + do: notify_on_error - send_complete_email: - action: core.sendmail - input: - to: "<% st2kv('system.napalm_remotebackup_mailto') %>" - from: "<% st2kv('system.napalm_remotebackup_mailfrom') %>" - subject: "Stackstorm completed a backup of <% $.hostname %>." - content_type: "text/plain" - body: "\r\nThe following syslog triggered this event: <% $.message %>\r\n\r\n - \r\n<% $.stderr %>\r\n - \r\n<% $.stdout %>\r\n - \r\n\r\n" + send_complete_email: + action: core.sendmail + input: + to: "{{ st2kv('system.napalm_remotebackup_mailto') }}" + from: "{{ st2kv('system.napalm_remotebackup_mailfrom') }}" + subject: "Stackstorm completed a backup of {{ ctx('hostname') }}." + content_type: "text/plain" + body: "\r\nThe following syslog triggered this event: {{ ctx('message') }}\r\n\r\n + \r\n{{ ctx('stderr') }}\r\n + \r\n{{ ctx('stdout') }}\r\n + \r\n\r\n" + + notify_on_error: + action: core.sendmail + input: + to: "{{ st2kv('system.napalm_actionerror_mailto') }}" + from: "{{ st2kv('system.napalm_actionerror_mailfrom') }}" + subject: "Stackstorm device backup workflow error" + body: "Something went wrong with the device backup workflow. Check stackstorm for the error. Execution ID {{ ctx('st2').action_execution_id }}\r\n\r\n" + next: + - do: fail - notify_on_error: - action: core.sendmail - input: - to: "<% st2kv('system.napalm_actionerror_mailto') %>" - from: "<% st2kv('system.napalm_actionerror_mailfrom') %>" - subject: "Stackstorm device backup workflow error" - body: "Something went wrong with the device backup workflow. Check stackstorm for the error. Execution ID <% env().st2_execution_id %>\r\n\r\n" - on-complete: - - fail +output: + - stdout: "{{ ctx('stdout') }}" + - stderr: "{{ ctx('stderr') }}" diff --git a/actions/workflows/interface_down_workflow.yaml b/actions/workflows/interface_down_workflow.yaml index 848f1e7..e26ccab 100644 --- a/actions/workflows/interface_down_workflow.yaml +++ b/actions/workflows/interface_down_workflow.yaml @@ -1,83 +1,114 @@ ---- - version: '2.0' +version: 1.0 - napalm.interface_down_workflow: +description: Interface Down Workflow - input: - - hostname - - message - - interface - - type: direct +input: + - hostname + - message + - interface - task-defaults: - on-error: - - notify_on_error +vars: + - show_interface_html: "" + - show_interface_counters_html: "" + - show_log_html: "" + - html_header: "" + - html_footer: "" - tasks: - - show_interface: - action: "napalm.get_interfaces" - input: - hostname: <% $.hostname %> - interface: <% $.interface %> - htmlout: true - on-success: "show_interface_counters" +tasks: + show_interface: + action: "napalm.get_interfaces" + input: + hostname: "{{ ctx('hostname') }}" + interface: "{{ ctx('interface') }}" + htmlout: true + next: + - when: "{{ succeeded() }}" + publish: + - show_interface_html: "{{ result().result.html }}" + do: show_interface_counters + - when: "{{ failed() }}" + do: notify_on_error - show_interface_counters: - action: "napalm.get_interfaces" - input: - hostname: <% $.hostname %> - interface: <% $.interface %> - htmlout: true - counters: true - on-success: "show_log" + show_interface_counters: + action: "napalm.get_interfaces" + input: + hostname: "{{ ctx('hostname') }}" + interface: "{{ ctx('interface') }}" + htmlout: true + counters: true + next: + - when: "{{ succeeded() }}" + publish: + - show_interface_counters_html: "{{ result().result.html }}" + do: show_log + - when: "{{ failed() }}" + do: notify_on_error - show_log: - action: "napalm.get_log" - input: - hostname: <% $.hostname %> - lastlines: 10 - htmlout: true - on-success: "get_html_header" + show_log: + action: "napalm.get_log" + input: + hostname: "{{ ctx('hostname') }}" + lastlines: 10 + htmlout: true + next: + - when: "{{ succeeded() }}" + publish: + - show_log_html: "{{ result().result.html }}" + do: get_html_header + - when: "{{ failed() }}" + do: notify_on_error - get_html_header: - action: "core.local" - input: - cmd: cat <% st2kv('system.napalm_html_mail_header_file') %> + get_html_header: + action: "core.local" + input: + cmd: "cat {{ st2kv('system.napalm_html_mail_header_file') }}" + next: + - when: "{{ succeeded() }}" publish: - html_header: <% task(get_html_header).result.stdout %> - on-success: "get_html_footer" + - html_header: "{{ result().stdout }}" + do: get_html_footer + - when: "{{ failed() }}" + do: notify_on_error - get_html_footer: - action: "core.local" - input: - cmd: cat <% st2kv('system.napalm_html_mail_footer_file') %> + get_html_footer: + action: "core.local" + input: + cmd: "cat {{ st2kv('system.napalm_html_mail_footer_file') }}" + next: + - when: "{{ succeeded() }}" publish: - html_footer: <% task(get_html_footer).result.stdout %> - on-success: "send_email" + - html_footer: "{{ result().stdout }}" + do: send_email + - when: "{{ failed() }}" + do: notify_on_error - send_email: - action: core.sendmail - input: - to: "<% st2kv('system.napalm_interface_down_mailto') %>" - from: "<% st2kv('system.napalm_interface_down_mailfrom') %>" - subject: "Interface <% $.interface %> is down on <% $.hostname %>." - content_type: "text/html" - body: "<% $.html_header %> -

The following syslog triggered this event: <% $.message %>

- <% task(show_interface).result.result.html %>

- <% task(show_interface_counters).result.result.html %>

- <% task(show_log).result.result.html %> - <% $.html_footer %> - " + send_email: + action: core.sendmail + input: + to: "{{ st2kv('system.napalm_interface_down_mailto') }}" + from: "{{ st2kv('system.napalm_interface_down_mailfrom') }}" + subject: "Interface {{ ctx('interface') }} is down on {{ ctx('hostname') }}." + content_type: "text/html" + body: "{{ ctx('html_header') }} +

The following syslog triggered this event: {{ ctx('message') }}

+ {{ ctx('show_interface_html') }}

+ {{ ctx('show_interface_counters_html') }}

+ {{ ctx('show_log_html') }} + {{ ctx('html_footer') }} + " + notify_on_error: + action: core.sendmail + input: + to: "{{ st2kv('system.napalm_actionerror_mailto') }}" + from: "{{ st2kv('system.napalm_actionerror_mailfrom') }}" + subject: "Stackstorm interface down workflow error" + body: "Something went wrong with the interface down workflow. Check stackstorm for the error. Execution ID {{ ctx('st2').action_execution_id }}\r\n\r\n" + next: + - do: fail - notify_on_error: - action: core.sendmail - input: - to: "<% st2kv('system.napalm_actionerror_mailto') %>" - from: "<% st2kv('system.napalm_actionerror_mailfrom') %>" - subject: "Stackstorm interface down workflow error" - body: "Something went wrong with the interface down workflow. Check stackstorm for the error. Execution ID <% env().st2_execution_id %>\r\n\r\n" - on-complete: - - fail +output: + - html_header: "{{ ctx('html_header') }}" + - show_interface_html: "{{ ctx('show_interface_html') }}" + - show_interface_counters_html: "{{ ctx('show_interface_counters_html') }}" + - show_log_html: "{{ ctx('show_log_html') }}" + - html_footer: "{{ ctx('html_footer') }}" diff --git a/pack.yaml b/pack.yaml index 832e66f..3dab1cd 100644 --- a/pack.yaml +++ b/pack.yaml @@ -7,7 +7,7 @@ keywords: - cisco - juniper - arista -version: 0.4.1 +version: 0.5.0 author: mierdin, Rob Woodward email: info@stackstorm.com python_versions: