Skip to content

Instantly share code, notes, and snippets.

View metabsd's full-sized avatar
🏠
Working from home

Benoit Martin metabsd

🏠
Working from home
View GitHub Profile
@metabsd
metabsd / gist:ba83bf0f54a50398c0996eb02b52c750
Created March 7, 2018 19:53
Need help with Ansible and conditionnal from uri module.
Ansible JMESPATH / JSON Explorer
nagios_xi_services.json.servicelist.service[?service_description=='Service Status: Filebeat'].host_name
I want to run a task when the result is empty only.
Example of data I register by module uri in nagios_xi_services
{
"nagios_xi_services": {
@metabsd
metabsd / gist:159366db2fed83813c7afd981282cc63
Created March 7, 2018 22:11
when status == 200 not working.
- name: Monitoring Filebeat Service
uri:
url: 'https://{{ nagios_server }}/nagiosxi/api/v1/config/service?apikey={{ nagios_api_key }}'
body: 'host_name={{ ansible_nodename }}&service_description={{ nagios_service_description }}&use={{ nagios_filebeat_template }}&force=1'
status_code: 200
method: POST
return_content: yes
validate_certs: no
timeout: 120
delegate_to: 127.0.0.1
tasks:
- name: add a new disk on guest vm
vmware_guest:
hostname: "{{ vcenter_hostname }}"
user: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ vcenter_datacenter }}"
cluster: "{{ vcenter_cluster }}"
guest_id: "rhel7_64Guest"
validate_certs: False
@metabsd
metabsd / gist:53582bfe3aeb3d3447938274c2246bf1
Created March 14, 2018 15:15
Debuging the result of searching in a Json result
I setup the variable.
- name: Set Nagios XI Services Facts
uri:
url: 'https://{{ nagios_server }}/nagiosxi/api/v1/objects/service?apikey={{ nagios_api_key }}&host_name=in:{{ ansible_play_hosts | join(",") }}'
status_code: 200
method: GET
return_content: yes
validate_certs: no
headers:
ok: [zltxct0863] => {
"nagios_xi_services.json.servicelist.service|selectattr('service_description', 'search', nagios_cpu_usage_service_description)|list": [
{
"@attributes": {
"id": "24244"
},
"action_url": "",
"active_checks_enabled": "1",
"check_interval": "15",
"config_type": "1",
@metabsd
metabsd / nagios_disk.py
Created March 16, 2018 15:03
Add disk in Nagios XI
if response_ncpa['root']['disk']['logical'][logical_disk]['fstype'] in ('xfs', 'ext3', 'ext4'):
# Classify DBA FS
if re.match(ymlregex.get('dba'), logical_disk_parse) is not None:
if not check_monitoring_exist(server['name'],'Disk Usage on ' + logical_disk_parse):
payload_dba = {'host_name': str(server['name']),
'use': nagiosxi_template,
'service_description': 'Disk Usage on ' + logical_disk_parse,
'check_command': 'check_xi_ncpa!-t \'' + ymltoken.get(
'linux') + '\' -P 5693 -M \'disk/logical/' + logical_disk + '\' -u M -w 90 -c 95!!!!!!!',
'force': '1'}
@metabsd
metabsd / ansible-disk.yml
Created March 16, 2018 15:18
First version
- name: Monitoring Disk Usage
vars:
fstype:
- xfs
- ext4
- ext3
debug: msg="Adding Monitoring to {{ item.mount }}"
with_items: ansible_mounts
when: fstype in item.fstype
---
#- hosts: en_utilisation:installed:&linux_red_hat:!production
- hosts: en_utilisation:installed:&sldadm*
- name: test for available disk space
assert:
that:
- not {{ item.mount == '/usr' and ( item.size_total <= 5368709120 ) }}
- not {{ item.mount == '/var' and ( item.size_total <= 5368709120 ) }}
msg: "{{ item.mount }} must be more than 5G"
with_items: "{{ ansible_mounts }}"
URL :
https://kibana.domain.name:5601/api/reporting/generate/printablePdf?jobParams=(browserTimezone:America%2FToronto,layout:(id:print),objectType:dashboard,queryString:%27_a%3D(description:!%27!%27,filters:!!(),fullScreenMode:!!f,options:(darkTheme:!!f,hidePanelTitles:!!f,useMargins:!!t),panels:!!((gridData:(h:3,i:!%271!%27,w:6,x:0,y:0),id:!%27429a2060-fa0f-11e7-b9c9-f5587aa8afb7!%27,panelIndex:!%271!%27,type:visualization,version:!%276.1.1!%27),(gridData:(h:3,i:!%272!%27,w:6,x:6,y:0),id:!%2707f5a070-fa13-11e7-b9c9-f5587aa8afb7!%27,panelIndex:!%272!%27,type:visualization,version:!%276.1.1!%27),(gridData:(h:3,i:!%273!%27,w:6,x:0,y:3),id:!%27953aa2a0-fa13-11e7-b9c9-f5587aa8afb7!%27,panelIndex:!%273!%27,type:visualization,version:!%276.1.1!%27),(gridData:(h:3,i:!%274!%27,w:6,x:6,y:3),id:a5c408a0-fa13-11e7-b9c9-f5587aa8afb7,panelIndex:!%274!%27,type:visualization,version:!%276.1.1!%27),(gridData:(h:3,i:!%275!%27,w:6,x:0,y:6),id:f5ed6d30-fa13-11e7-b9c9-f5587aa8afb7,panelIndex:!%275!%27,type:visualization,versio

Debug

Kubernetes deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: '18'