-
Notifications
You must be signed in to change notification settings - Fork 18
/
mtk-probe-tshoot-notification-api.yml
151 lines (131 loc) · 5.04 KB
/
mtk-probe-tshoot-notification-api.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
---
- name: Reach out to remote probes and troubleshoot routing
hosts: all
gather_facts: no
vars:
ansible_command_timeout: 120
destIP: 1.1.1.1
srcIP: 0.0.0.0
send_slack: True
send_email: False
send_snow: False
email_host: smtp.gmail.com
email_port: 587
email_to: Greg Sowell <[email protected]>
email_subject: Ansible-report
# email_user: [email protected]
# email_pword: password-for-gmail-account
slack_channel: '#ansible'
# slack_token: thisis/thetoken/givenbyslackwebhook
# snow_username: admin
# snow_password: mysnowpword
# snow_instance: dev99999
# snow_caller_id: Abel Tuter
snow_caller_id: System Administrator
tasks:
- name: Ping Destination
routeros_command:
commands:
- "/ping count=10 {{ destIP }}"
register: pings
- name: Ping Source
routeros_command:
commands:
- "/ping count=10 {{ srcIP }}"
register: pings_source
when: srcIP != "0.0.0.0"
- name: Traceroute Destinations
routeros_command:
commands:
- "/tool traceroute count=1 {{ destIP }}"
register: traces
- name: Traceroute source
routeros_command:
commands:
- "/tool traceroute count=1 {{ srcIP }}"
register: traces_source
when: srcIP != "0.0.0.0"
- name: display output for no source
set_fact:
send_msg: "##################Testing to {{ destIP }}##################\n##################{{ inventory_hostname }}##################\n===pings===\n{{ pings.stdout|join('\n') }}\n===traces===\n{{ traces.stdout|join('\n') }}\n\n"
when: srcIP == "0.0.0.0"
- name: display output with source
set_fact:
send_msg: "##################Testing to {{ destIP }}##################\n##################{{ inventory_hostname }}##################\n===pings destination===\n{{ pings.stdout|join('\n') }}\n===traces destination===\n{{ traces.stdout|join('\n') }}\n===pings source===\n{{ pings_source.stdout|join('\n') }}\n===traces source===\n{{ traces_source.stdout|join('\n') }}\n\n"
when: srcIP != "0.0.0.0"
- name: create SNOW incident
when: send_snow
run_once: True
ignore_errors: True
block:
- name: Create an incident
snow_record:
username: "{{ snow_username }}"
password: "{{ snow_password }}"
instance: "{{ snow_instance }}"
state: present
data:
short_description: "Zab-Tower - Device Down - {{ destIP }}"
# description: Something here useful
caller_id: "{{ snow_caller_id }}"
severity: 3
priority: 5
register: new_incident
- set_fact:
ticket_number: "{{ new_incident.record.number }}"
- name: debug new_incident
when: ticket_number is defined
run_once: True
debug:
msg: "Ticket Number is: {{ ticket_number | default('None')}}"
- name: create SNOW incident
when: send_snow
ignore_errors: True
block:
- name: Add pings
snow_record:
username: "{{ snow_username }}"
password: "{{ snow_password }}"
instance: "{{ snow_instance }}"
state: present
number: "{{ ticket_number }}"
data:
comments: "##################{{ inventory_hostname }}##################\n===pings===\n{{ pings.stdout|join('\n') }}\n"
- name: Add traces
snow_record:
username: "{{ snow_username }}"
password: "{{ snow_password }}"
instance: "{{ snow_instance }}"
state: present
number: "{{ ticket_number }}"
data:
comments: "##################{{ inventory_hostname }}##################\n===traces===\n{{ traces.stdout|join('\n') }}\n"
- name: send message through slack
when: send_slack
slack:
token: "{{ slack_token }}"
# msg: |
# "SNOW ticket {{ new_incident.record.number | default('None')}}"
# "{{ send_msg }}"
attachments:
- text: "{{ send_msg }}"
title: "SNOW ticket {{ new_incident.record.number | default('None')}}"
title_link: "https://{{ snow_instance }}.service-now.com/nav_to.do?uri=incident.do?sysparm_query=number={{ new_incident.record.number | default('None')}}"
channel: "{{ slack_channel }}"
# thread_id: 1539917263.000100
parse: 'none'
delegate_to: localhost
- name: Sending an e-mail using Gmail SMTP servers
when: send_email
mail:
host: "{{ email_host }}"
port: "{{ email_port }}"
username: "{{ email_user }}"
password: "{{ email_pword }}"
to: "{{ email_to }}"
subject: "{{ email_subject }}"
# body: "{{ send_msg }}"
body: |
"SNOW ticket https://{{ snow_instance }}.service-now.com/nav_to.do?uri=incident.do?sysparm_query=number={{ new_incident.record.number | default('None')}}"
"{{ send_msg }}"
delegate_to: localhost