Compare commits

..

28 Commits

Author SHA1 Message Date
3c7e7ea20c No log 2024-05-02 10:29:33 -04:00
63e783e7f6 Set file perms 2024-04-19 13:29:28 -04:00
4a2c09cc9d Text plain 2024-04-17 15:50:02 -04:00
4e83e7fc3b Fix delegation 2024-04-17 15:45:58 -04:00
ae35d3d7e0 Modify attachment 2024-04-17 15:38:28 -04:00
de71c93bdc Add Snow Instance info 2024-04-17 15:31:47 -04:00
28c0cd80e4 Add more information 2024-04-17 14:32:23 -04:00
fa70098229 Fix paths to vars 2024-04-17 14:12:26 -04:00
e3e5438db4 Update playbook to talk to SNOW 2024-04-17 14:01:23 -04:00
48a1e5b35f Remove problematic attribute 2024-04-17 13:47:33 -04:00
1d20c23b2c Fix rulebook 2024-04-17 13:40:56 -04:00
de78f7d085 Fix Typo 2024-04-17 13:24:01 -04:00
e5ec521ec4 Add playbooks and templates for CPUHog 2024-04-17 13:16:41 -04:00
5707153521 Add High CPU Investitgaion. 2024-04-17 11:33:40 -04:00
bcc1ca96c0 Update container-compose.yml 2024-03-08 12:05:21 -05:00
87d378d1b5 Update appwrite to 1.5.1 2024-03-08 11:58:48 -05:00
c34b2e96c2 Escalate privilege and be selective about filename 2024-01-18 12:26:06 -05:00
2a1f83fdd4 Add some logging 2024-01-18 12:22:25 -05:00
7056507aa9 Working alertmanager source. Starting playbook to clean logfiles 2024-01-18 07:59:42 -05:00
7b5eac7ad1 Add data and template name 2024-01-17 08:11:46 -05:00
b21229b82f Update condition and source 2024-01-17 07:44:30 -05:00
242ae46780 Still testing 2024-01-17 07:39:09 -05:00
e0dfbabcea Try a webhook 2024-01-17 07:21:29 -05:00
6a46878c8f Test 2024-01-16 23:05:34 -05:00
1a30881d5d Update condition 2024-01-16 22:49:40 -05:00
27f8818cef Update condition 2024-01-16 22:47:03 -05:00
d0b413d762 Add debugj 2024-01-16 22:39:45 -05:00
ea5f34723e Change listening port to 9101 2024-01-16 17:58:58 -05:00
9 changed files with 206 additions and 13 deletions

29
playbooks/clean_logs.yml Normal file
View File

@@ -0,0 +1,29 @@
---
- name: Clean log directory
hosts: all
become: true
tasks:
- name: Find files in directory ending in .log or .log.tgz larger than 1GB
ansible.builtin.find:
paths: /var/log
patterns: 'testlog.*'
size: 1g
register: logfiles
# - name: Copy files to archive server
# ansible.builtin.copy:
# src: "{{ item.path }}"
# dest: "{{ archive_server_path }}/{{ item.path | basename }}"
# delegate_to: "{{ archive_server }}"
# loop: "{{ logfiles.files |flatten(levels=1) }}"
- name: Delete files
ansible.builtin.file:
path: "{{ item.path }}"
state: absent
loop: "{{ logfiles.files | flatten(levels=1) }}"
register: deleted_files
- name: Dump details on deletion
ansible.builtin.debug:
var: deleted_files

View File

@@ -47,10 +47,10 @@
- name: Ensure appwrite image pulled from docker hub
containers.podman.podman_image:
name: docker.io/appwrite/appwrite
tag: 1.4.13
tag: 1.5.1
- name: Ensure podman-compose.yml deployed
ansible.builtin.copy:
src: podman-compose.yml
src: files/container-compose.yml
dest: /home/ptoal/appwrite
mode: '0644'

View File

@@ -3,7 +3,10 @@
hosts: all
become: true
tasks:
# This is incomplete
# - name: Certificates Installed
# ansible.builtin.include_tasks:
# file: upate_certificates.yml
- name: Nginx Installed
ansible.builtin.include_role:
name: nginxinc.nginx_core.nginx

View File

@@ -0,0 +1,62 @@
---
- name: Investigate High CPU
hosts: all
become: true
tasks:
- name: Gather information on top CPU consuming processes
ansible.builtin.command:
cmd: 'ps -eo pid,ppid,%mem,%cpu,cmd --sort=-%cpu'
register: processes_cpu
changed_when: false
- name: Gather information on top Memory consuming processes
ansible.builtin.command:
cmd: 'ps -eo pid,ppid,%mem,%cpu,cmd --sort=-%mem'
register: processes_mem
changed_when: false
- name: Open Incident
hosts: all
tasks:
- name: Create Problem Template # noqa: no-relative-paths
ansible.builtin.template:
mode: '0644'
src: '../templates/cpuhog_ticket.j2'
dest: /tmp/cpuhog_details.txt
delegate_to: localhost
- name: Create SNow Incident
servicenow.itsm.incident:
instance: '{{ snow_instance }}'
state: new
caller: "admin"
short_description: "CPUHog event detected on: {{ ansible_eda.event.alert.labels.instance }}"
description: "A CPUHog was detected on: {{ ansible_eda.event.alert.labels.instance }} that needs to be investigated."
impact: high
urgency: high
delegate_to: localhost
register: incident_result
- name: Create SNow Problem
servicenow.itsm.problem:
instance: '{{ snow_instance }}'
state: new
short_description: "{{ alertmanager_annotations.summary }}"
description: "Generator URL: {{ alertmanager_generator_url }}"
impact: high
urgency: high
attachments:
- path: /tmp/cpuhog_details.txt
name: cpuhog_details.txt
type: 'text/plain'
register: problem_result
delegate_to: localhost
- name: Update Incident
servicenow.itsm.incident:
instance: '{{ snow_instance }}'
state: in_progress
number: "{{ incident_result.record.number }}"
other:
problem_id: "{{ problem_result.record.number }}"
delegate_to: localhost

View File

@@ -24,6 +24,7 @@
register: appwrite_api_result
loop: '{{ bab_users }}'
delegate_to: localhost
no_log: true
- name: Display response
ansible.builtin.debug:

View File

@@ -0,0 +1,51 @@
---
- name: Request and INstall Certs from Red Hat IdM
hosts: webservers
become: true
tasks:
- name: Ensure the IPA client and OpenSSL are installed
ansible.builtin.package:
name:
- ipa-client
- openssl
state: present
- name: Generate private key
community.crypto.openssl_privatekey:
path: "{{ key_path }}"
size: 2048
- name: Generate CSR
community.crypto.openssl_csr:
path: "{{ csr_path }}"
privatekey_path: "{{ key_path }}"
common_name: "{{ ansible_fqdn }}"
subject: "{{ cert_subject }}"
key_usage:
- digitalSignature
- keyEncipherment
extended_key_usage:
- serverAuth
- name: Request a certificate from IdM
redhat.rhel_idm.ipacert:
ipaadmin_password: "{{ ipa_admin_password }}"
csr_path: "{{ csr_path }}"
principal: "HTTP/{{ ansible_fqdn }}@{{ ipa_domain }}"
cert_profile: "HTTP_Server"
cert_out_path: "{{ cert_path }}"
register: cert_result
- name: Install the certificate
ansible.builtin.copy:
content: "{{ cert_result.certificate }}"
dest: "{{ cert_path }}"
notify:
- restart web server
handlers:
- name: restart web server
ansible.builtin.service:
name: httpd
state: restarted

View File

@@ -4,17 +4,45 @@
sources:
- name: Ansible Alertmanager listener
ansible.eda.alertmanager:
port: 9100
port: 9101
host: 0.0.0.0
rules:
- name: Run Template
- name: Resolve Disk Usage
condition:
all:
- event.payload.data.artifact_url is defined
action:
run_job_template:
name: bab-deploy-application
organization: OYS
job_args:
extra_vars:
artifact_url: "{{ event.payload.data.artifact_url }}"
- event.alert.labels.org == "OYS" and event.alert.status == "firing"
and event.alert.labels.alertname == "root filesystem over 80% full"
actions:
- run_job_template:
name: Demo - Clean Log Directory
organization: OYS
job_args:
extra_vars:
alertmanager_annotations: "{{ event.alert.annotations }}"
alertmanager_generator_url: "{{ event.alert.generatorURL }}"
event_mountpoint: "{{ event.alert.labels.mountpoint }}"
alertmanager_instance: "{{ event.alert.labels.instance }}"
- name: Investigate High CPU
condition:
all:
- event.alert.labels.org == "OYS" and event.alert.status == "firing"
and event.alert.labels.alertname == "ProcessCPUHog"
actions:
- print_event:
pretty: true
- run_job_template:
name: Demo - Investigate High CPU
organization: OYS
job_args:
extra_vars:
alertmanager_annotations: "{{ event.alert.annotations }}"
alertmanager_generator_url: "{{ event.alert.generatorURL }}"
event_severity: "{{ event.alert.labels.severity }}"
alertmanager_instance: "{{ event.alert.labels.instance }}"
- name: Test Contact Point
condition: event.alert.labels.alertname == "TestAlert" and event.alert.labels.org == "OYS"
actions:
- print_event:
pretty: true

View File

@@ -0,0 +1,19 @@
= CPUHog Report =
A high CPU event was triggered from AlertManager.
{% if ansible_eda is defined %}
Annotations: "{{ ansible_eda.event.alert.annotations }}"
Generator URL: "{{ ansible_eda.event.alert.generatorURL }}"
Severity: "{{ ansible_eda.event.alert.labels.severity }}"
Instance: "{{ ansible_eda.event.alert.labels.instance }}"
{% endif %}
** Top CPU Consumers **
{% for line in processes_cpu.stdout_lines[0:10] %}
{{ line }}
{% endfor %}
** Top Memory Consumers **
{% for line in processes_mem.stdout_lines[0:10] %}
{{ line }}
{% endfor %}