Native YAML - monitoring/logicmonitor.py (#18790)

* Native YAML - monitoring/logicmonitor.py

* Fix comments as well

* Fix quotes
This commit is contained in:
Fabio Alessandro Locati 2016-12-07 01:41:29 +00:00 committed by Matt Clay
parent 8e951b9f98
commit c786f7ca3c

View file

@ -89,7 +89,7 @@ options:
- NOTE You should use Ansible service modules such as M(service) or M(supervisorctl) for managing the Collector 'logicmonitor-agent' and 'logicmonitor-watchdog' services. Specifically, you'll probably want to start these services after a Collector add and stop these services before a Collector remove. - NOTE You should use Ansible service modules such as M(service) or M(supervisorctl) for managing the Collector 'logicmonitor-agent' and 'logicmonitor-watchdog' services. Specifically, you'll probably want to start these services after a Collector add and stop these services before a Collector remove.
- "Host: Perform actions on a host device." - "Host: Perform actions on a host device."
- "Hostgroup: Perform actions on a LogicMonitor host group." - "Hostgroup: Perform actions on a LogicMonitor host group."
- NOTE Host and Hostgroup tasks should always be performed via local_action. There are no benefits to running these tasks on the remote host and doing so will typically cause problems. - 'NOTE Host and Hostgroup tasks should always be performed via delegate_to: localhost. There are no benefits to running these tasks on the remote host and doing so will typically cause problems.'
required: true required: true
default: null default: null
choices: ['collector', 'host', 'datsource', 'hostgroup'] choices: ['collector', 'host', 'datsource', 'hostgroup']
@ -192,352 +192,367 @@ options:
... ...
''' '''
EXAMPLES = ''' EXAMPLES = '''
# example of adding a new LogicMonitor collector to these devices # example of adding a new LogicMonitor collector to these devices
--- ---
- hosts: collectors - hosts: collectors
remote_user: '{{ username }}' remote_user: '{{ username }}'
vars: vars:
company: 'mycompany' company: mycompany
user: 'myusername' user: myusername
password: 'mypassword' password: mypassword
tasks: tasks:
- name: Deploy/verify LogicMonitor collectors - name: Deploy/verify LogicMonitor collectors
become: yes become: yes
logicmonitor: logicmonitor:
target=collector target: collector
action=add action: add
company={{ company }} company: '{{ company }}'
user={{ user }} user: '{{ user }}'
password={{ password }} password: '{{ password }}'
#example of adding a list of hosts into monitoring #example of adding a list of hosts into monitoring
--- ---
- hosts: hosts - hosts: hosts
remote_user: '{{ username }}' remote_user: '{{ username }}'
vars: vars:
company: 'mycompany' company: mycompany
user: 'myusername' user: myusername
password: 'mypassword' password: mypassword
tasks: tasks:
- name: Deploy LogicMonitor Host - name: Deploy LogicMonitor Host
# All tasks except for target=collector should use local_action # All tasks except for target=collector should use delegate_to: localhost
local_action: > logicmonitor:
logicmonitor target: host
target=host action: add
action=add collector: mycompany-Collector
collector='mycompany-Collector' company: '{{ company }}'
company='{{ company }}' user: '{{ user }}'
user='{{ user }}' password: '{{ password }}'
password='{{ password }}' groups: /servers/production,/datacenter1
groups="/servers/production,/datacenter1" properties:
properties="{'snmp.community':'secret','dc':'1', 'type':'prod'}" snmp.community: secret
dc: 1
type: prod
delegate_to: localhost
#example of putting a datasource in SDT #example of putting a datasource in SDT
--- ---
- hosts: localhost - hosts: localhost
remote_user: '{{ username }}' remote_user: '{{ username }}'
vars: vars:
company: 'mycompany' company: mycompany
user: 'myusername' user: myusername
password: 'mypassword' password: mypassword
tasks: tasks:
- name: SDT a datasource - name: SDT a datasource
# All tasks except for target=collector should use local_action # All tasks except for target=collector should use delegate_to: localhost
local_action: > logicmonitor:
logicmonitor target: datasource
target=datasource action: sdt
action=sdt id: 123
id='123' duration: 3000
duration=3000 starttime: '2017-03-04 05:06'
starttime='2017-03-04 05:06' company: '{{ company }}'
company='{{ company }}' user: '{{ user }}'
user='{{ user }}' password: '{{ password }}'
password='{{ password }}'
#example of creating a hostgroup #example of creating a hostgroup
--- ---
- hosts: localhost - hosts: localhost
remote_user: '{{ username }}' remote_user: '{{ username }}'
vars: vars:
company: 'mycompany' company: mycompany
user: 'myusername' user: myusername
password: 'mypassword' password: mypassword
tasks: tasks:
- name: Create a host group - name: Create a host group
# All tasks except for target=collector should use local_action # All tasks except for target=collector should use delegate_to: localhost
local_action: > logicmonitor
logicmonitor target: hostgroup
target=hostgroup action: add
action=add fullpath: /servers/development
fullpath='/servers/development' company: '{{ company }}'
company='{{ company }}' user: '{{ user }}'
user='{{ user }}' password: '{{ password }}'
password='{{ password }}' properties:
properties="{'snmp.community':'commstring', 'type':'dev'}" snmp.community: commstring
type: dev
#example of putting a list of hosts into SDT #example of putting a list of hosts into SDT
--- ---
- hosts: hosts - hosts: hosts
remote_user: '{{ username }}' remote_user: '{{ username }}'
vars: vars:
company: 'mycompany' company: mycompany
user: 'myusername' user: myusername
password: 'mypassword' password: mypassword
tasks: tasks:
- name: SDT hosts - name: SDT hosts
# All tasks except for target=collector should use local_action # All tasks except for target=collector should use delegate_to: localhost
local_action: > logicmonitor:
logicmonitor target: host
target=host action: sdt
action=sdt duration: 3000
duration=3000 starttime: '2016-11-10 09:08'
starttime='2016-11-10 09:08' company: '{{ company }}'
company='{{ company }}' user: '{{ user }}'
user='{{ user }}' password: '{{ password }}'
password='{{ password }}' collector: mycompany-Collector
collector='mycompany-Collector' delegate_to: localhost
#example of putting a host group in SDT #example of putting a host group in SDT
--- ---
- hosts: localhost - hosts: localhost
remote_user: '{{ username }}' remote_user: '{{ username }}'
vars: vars:
company: 'mycompany' company: mycompany
user: 'myusername' user: myusername
password: 'mypassword' password: mypassword
tasks: tasks:
- name: SDT a host group - name: SDT a host group
# All tasks except for target=collector should use local_action # All tasks except for target=collector should use delegate_to: localhost
local_action: > logicmonitor:
logicmonitor target: hostgroup
target=hostgroup action: sdt
action=sdt fullpath: /servers/development
fullpath='/servers/development' duration: 3000
duration=3000 starttime: '2017-03-04 05:06'
starttime='2017-03-04 05:06' company=: '{{ company }}'
company='{{ company }}' user: '{{ user }}'
user='{{ user }}' password: '{{ password }}'
password='{{ password }}'
#example of updating a list of hosts #example of updating a list of hosts
--- ---
- hosts: hosts - hosts: hosts
remote_user: '{{ username }}' remote_user: '{{ username }}'
vars: vars:
company: 'mycompany' company: mycompany
user: 'myusername' user: myusername
password: 'mypassword' password: mypassword
tasks: tasks:
- name: Update a list of hosts - name: Update a list of hosts
# All tasks except for target=collector should use local_action # All tasks except for target=collector should use delegate_to: localhost
local_action: > logicmonitor:
logicmonitor target: host
target=host action: update
action=update company: '{{ company }}'
company='{{ company }}' user: '{{ user }}'
user='{{ user }}' password: '{{ password }}'
password='{{ password }}' collector: mycompany-Collector
collector='mycompany-Collector' groups: /servers/production,/datacenter5
groups="/servers/production,/datacenter5" properties:
properties="{'snmp.community':'commstring','dc':'5'}" snmp.community: commstring
dc: 5
delegate_to: localhost
#example of updating a hostgroup #example of updating a hostgroup
--- ---
- hosts: hosts - hosts: hosts
remote_user: '{{ username }}' remote_user: '{{ username }}'
vars: vars:
company: 'mycompany' company: mycompany
user: 'myusername' user: myusername
password: 'mypassword' password: mypassword
tasks: tasks:
- name: Update a host group - name: Update a host group
# All tasks except for target=collector should use local_action # All tasks except for target=collector should use delegate_to: localhost
local_action: > logicmonitor:
logicmonitor target: hostgroup
target=hostgroup action: update
action=update fullpath: /servers/development
fullpath='/servers/development' company: '{{ company }}'
company='{{ company }}' user: '{{ user }}'
user='{{ user }}' password: '{{ password }}'
password='{{ password }}' properties:
properties="{'snmp.community':'hg', 'type':'dev', 'status':'test'}" snmp.community: hg
type: dev
status: test
delegate_to: localhost
#example of removing a list of hosts from monitoring #example of removing a list of hosts from monitoring
--- ---
- hosts: hosts - hosts: hosts
remote_user: '{{ username }}' remote_user: '{{ username }}'
vars: vars:
company: 'mycompany' company: mycompany
user: 'myusername' user: myusername
password: 'mypassword' password: mypassword
tasks: tasks:
- name: Remove LogicMonitor hosts - name: Remove LogicMonitor hosts
# All tasks except for target=collector should use local_action # All tasks except for target=collector should use delegate_to: localhost
local_action: > logicmonitor:
logicmonitor target: host
target=host action: remove
action=remove company: '{{ company }}'
company='{{ company }}' user: '{{ user }}'
user='{{ user }}' password: '{{ password }}'
password='{{ password }}' collector: mycompany-Collector
collector='mycompany-Collector' delegate_to: localhost
#example of removing a host group #example of removing a host group
--- ---
- hosts: hosts - hosts: hosts
remote_user: '{{ username }}' remote_user: '{{ username }}'
vars: vars:
company: 'mycompany' company: mycompany
user: 'myusername' user: myusername
password: 'mypassword' password: mypassword
tasks: tasks:
- name: Remove LogicMonitor development servers hostgroup - name: Remove LogicMonitor development servers hostgroup
# All tasks except for target=collector should use local_action # All tasks except for target=collector should use delegate_to: localhost
local_action: > logicmonitor:
logicmonitor target: hostgroup
target=hostgroup action: remove
action=remove company: '{{ company }}'
company='{{ company }}' user: '{{ user }}'
user='{{ user }}' password: '{{ password }}'
password='{{ password }}' fullpath: /servers/development
fullpath='/servers/development' delegate_to: localhost
- name: Remove LogicMonitor servers hostgroup - name: Remove LogicMonitor servers hostgroup
# All tasks except for target=collector should use local_action # All tasks except for target=collector should use delegate_to: localhost
local_action: > logicmonitor:
logicmonitor target: hostgroup
target=hostgroup action: remove
action=remove company: '{{ company }}'
company='{{ company }}' user: '{{ user }}'
user='{{ user }}' password: '{{ password }}'
password='{{ password }}' fullpath: /servers
fullpath='/servers' delegate_to: localhost
- name: Remove LogicMonitor datacenter1 hostgroup - name: Remove LogicMonitor datacenter1 hostgroup
# All tasks except for target=collector should use local_action # All tasks except for target=collector should use delegate_to: localhost
local_action: > logicmonitor:
logicmonitor target: hostgroup
target=hostgroup action: remove
action=remove company: '{{ company }}'
company='{{ company }}' user: '{{ user }}'
user='{{ user }}' password: '{{ password }}'
password='{{ password }}' fullpath: /datacenter1
fullpath='/datacenter1' delegate_to: localhost
- name: Remove LogicMonitor datacenter5 hostgroup - name: Remove LogicMonitor datacenter5 hostgroup
# All tasks except for target=collector should use local_action # All tasks except for target=collector should use delegate_to: localhost
local_action: > logicmonitor:
logicmonitor target: hostgroup
target=hostgroup action: remove
action=remove company: '{{ company }}'
company='{{ company }}' user: '{{ user }}'
user='{{ user }}' password: '{{ password }}'
password='{{ password }}' fullpath: /datacenter5
fullpath='/datacenter5' delegate_to: localhost
### example of removing a new LogicMonitor collector to these devices ### example of removing a new LogicMonitor collector to these devices
--- ---
- hosts: collectors - hosts: collectors
remote_user: '{{ username }}' remote_user: '{{ username }}'
vars: vars:
company: 'mycompany' company: mycompany
user: 'myusername' user: myusername
password: 'mypassword' password: mypassword
tasks: tasks:
- name: Remove LogicMonitor collectors - name: Remove LogicMonitor collectors
become: yes become: yes
logicmonitor: logicmonitor:
target=collector target: collector
action=remove action: remove
company={{ company }} company: '{{ company }}'
user={{ user }} user: '{{ user }}'
password={{ password }} password: '{{ password }}'
#complete example #complete example
--- ---
- hosts: localhost - hosts: localhost
remote_user: '{{ username }}' remote_user: '{{ username }}'
vars: vars:
company: 'mycompany' company: mycompany
user: 'myusername' user: myusername
password: 'mypassword' password: mypassword
tasks: tasks:
- name: Create a host group - name: Create a host group
local_action: > logicmonitor:
logicmonitor target: hostgroup
target=hostgroup action: add
action=add fullpath: /servers/production/database
fullpath='/servers/production/database' company: '{{ company }}'
company='{{ company }}' user: '{{ user }}'
user='{{ user }}' password: '{{ password }}'
password='{{ password }}' properties:
properties="{'snmp.community':'commstring'}" snmp.community: commstring
- name: SDT a host group - name: SDT a host group
local_action: > logicmonitor:
logicmonitor target: hostgroup
target=hostgroup action: sdt
action=sdt fullpath: /servers/production/web
fullpath='/servers/production/web' duration: 3000
duration=3000 starttime: '2012-03-04 05:06'
starttime='2012-03-04 05:06' company: '{{ company }}'
company='{{ company }}' user: '{{ user }}'
user='{{ user }}' password: '{{ password }}'
password='{{ password }}'
- hosts: collectors - hosts: collectors
remote_user: '{{ username }}' remote_user: '{{ username }}'
vars: vars:
company: 'mycompany' company: mycompany
user: 'myusername' user: myusername
password: 'mypassword' password: mypassword
tasks: tasks:
- name: Deploy/verify LogicMonitor collectors - name: Deploy/verify LogicMonitor collectors
logicmonitor: logicmonitor:
target: collector target: collector
action: add action: add
company: {{ company }} company: '{{ company }}'
user: {{ user }} user: '{{ user }}'
password: {{ password }} password: '{{ password }}'
- name: Place LogicMonitor collectors into 30 minute Scheduled downtime - name: Place LogicMonitor collectors into 30 minute Scheduled downtime
logicmonitor: target=collector action=sdt company={{ company }} logicmonitor:
user={{ user }} password={{ password }} target: collector
- name: Deploy LogicMonitor Host action: sdt
local_action: > company: '{{ company }}'
logicmonitor user: '{{ user }}'
target=host password: '{{ password }}'
action=add - name: Deploy LogicMonitor Host
collector=agent1.ethandev.com logicmonitor:
company='{{ company }}' target: host
user='{{ user }}' action: add
password='{{ password }}' collector: agent1.ethandev.com
properties="{'snmp.community':'commstring', 'dc':'1'}" company: '{{ company }}'
groups="/servers/production/collectors, /datacenter1" user: '{{ user }}'
password: '{{ password }}'
properties:
snmp.community: commstring
dc: 1
groups: /servers/production/collectors, /datacenter1
delegate_to: localhost
- hosts: database-servers - hosts: database-servers
remote_user: '{{ username }}' remote_user: '{{ username }}'
vars: vars:
company: 'mycompany' company: mycompany
user: 'myusername' user: myusername
password: 'mypassword' password: mypassword
tasks: tasks:
- name: deploy logicmonitor hosts - name: deploy logicmonitor hosts
local_action: > logicmonitor:
logicmonitor target: host
target=host action: add
action=add collector: monitoring.dev.com
collector=monitoring.dev.com company: '{{ company }}'
company='{{ company }}' user: '{{ user }}'
user='{{ user }}' password: '{{ password }}'
password='{{ password }}' properties:
properties="{'snmp.community':'commstring', 'type':'db', 'dc':'1'}" snmp.community: commstring
groups="/servers/production/database, /datacenter1" type: db
- name: schedule 5 hour downtime for 2012-11-10 09:08 dc: 1
local_action: > groups: /servers/production/database, /datacenter1
logicmonitor delegate_to: localhost
target=host - name: schedule 5 hour downtime for 2012-11-10 09:08
action=sdt logicmonitor:
duration=3000 target: host
starttime='2012-11-10 09:08' action: sdt
company='{{ company }}' duration: 3000
user='{{ user }}' starttime: '2012-11-10 09:08'
password='{{ password }}' company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
delegate_to: localhost
''' '''