⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions playbooks/iag_fakenos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# Copyright (c) 2024, Itential, Inc
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)

- name: Install and run Fakenos on mock hosts
hosts: gateway
become: true
become_user: itential
roles:
- fakenos
125 changes: 45 additions & 80 deletions playbooks/metrics.yml
Original file line number Diff line number Diff line change
@@ -1,114 +1,79 @@
# Copyright (c) 2023, Itential, LLC
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
---
# Example usage:
# ansible-playbook -i hosts metrics.yml
- name: IAP Metrics
hosts: platform
gather_facts: false
roles:
- itential.toolkit.auth_token
vars:
ansible_connection: local
tasks:

- name: Login to IAP and get token
ansible.builtin.uri:
url: "{{ iap_protocol }}://{{ ansible_host }}:{{ iap_port }}/login"
method: POST
body: '{"username": "{{ iap_username }}", "password": "{{ iap_password }}"}'
body_format: json
headers:
Content-Type: "application/json"
status_code: 200
return_content: true
register: token

- name: Extract token from login response
ansible.builtin.set_fact:
auth_token: "?token={{ token.content }}"

- name: Get workflow count
ansible.builtin.uri:
url: "{{ iap_protocol }}://{{ ansible_host }}:{{ iap_port }}/automation-studio/workflows{{ auth_token }}"
itential.platform.generic_request:
method: GET
status_code: 200
return_content: true
endpoint: "/automation-studio/workflows"
params:
include: "_id"
limit: 0
register: workflows

- name: Get template count
ansible.builtin.uri:
url: "{{ iap_protocol }}://{{ ansible_host }}:{{ iap_port }}/automation-studio/templates{{ auth_token }}"
itential.platform.generic_request:
method: GET
status_code: 200
return_content: true
endpoint: "/automation-studio/templates"
params:
include: "_id"
register: templates

- name: Get transformation count
ansible.builtin.uri:
url: "{{ iap_protocol }}://{{ ansible_host }}:{{ iap_port }}/transformations{{ auth_token }}"
itential.platform.generic_request:
method: GET
status_code: 200
return_content: true
endpoint: "/transformations"
params:
include: "_id"
limit: 0
register: transformations

- name: Get MOP templates count
ansible.builtin.uri:
url: "{{ iap_protocol }}://{{ ansible_host }}:{{ iap_port }}/mop/listTemplates{{ auth_token }}"
method: GET
status_code: 200
return_content: true
register: mop

- name: Get analytic templates count
ansible.builtin.uri:
url: "{{ iap_protocol }}://{{ ansible_host }}:{{ iap_port }}/mop/listAnalyticTemplates{{ auth_token }}"
method: GET
status_code: 200
return_content: true
register: analytictemplates

- name: Get jobs count
ansible.builtin.uri:
url: "{{ iap_protocol }}://{{ ansible_host }}:{{ iap_port }}/operations-manager/jobs{{ auth_token }}"
method: GET
status_code: 200
return_content: true
itential.platform.get_jobs:
register: jobs

- name: Get automations count
ansible.builtin.uri:
url: "{{ iap_protocol }}://{{ ansible_host }}:{{ iap_port }}/operations-manager/automations{{ auth_token }}"
method: GET
status_code: 200
return_content: true
register: automations

- name: Get form count
ansible.builtin.uri:
url: "{{ iap_protocol }}://{{ ansible_host }}:{{ iap_port }}/formbuilder/listForms{{ auth_token }}"
method: GET
status_code: 200
return_content: true
register: forms
- name: Set paused and errored job counts
ansible.builtin.set_fact:
paused_job_count: "{{ jobs.json.data | selectattr('status', 'equalto', 'paused') | list | length }}"
errored_job_count: "{{ jobs.json.data | selectattr('status', 'equalto', 'error') | list | length }}"

- name: Get json form count
ansible.builtin.uri:
url: "{{ iap_protocol }}://{{ ansible_host }}:{{ iap_port }}/json-forms/forms{{ auth_token }}"
itential.platform.generic_request:
method: GET
status_code: 200
return_content: true
endpoint: "/json-forms/forms"
params:
include: "_id"
limit: 0
register: jsonforms

- name: Get count of active manual tasks
itential.platform.get_tasks:
status: running
register: active_tasks

- name: Set manual task count
ansible.builtin.set_fact:
manual_task_count: "{{ active_tasks.json.data | selectattr('type', 'equalto', 'manual') | list | length }}"

- name: Display metrics
ansible.builtin.debug:
msg:
- "Metrics of {{ iap_protocol }}://{{ ansible_host }}:{{ iap_port }}"
- "Metrics of {{ ansible_host }}"
- "====================================================="
- "Workflow count: {{ workflows.json.count }} "
- "Template count: {{ templates.json.count }} "
- "MOP template count: {{ mop.json | length }} "
- "Analytic template count: {{ analytictemplates.json | length }} "
- "JST count: {{ transformations.json.total }} "
- "JSON form count: {{ jsonforms.json | length }} "
- "Form count: {{ forms.json | length }} "
- "Job count: {{ jobs.json.metadata.total }} "
- "Automation count: {{ automations.json.metadata.total }} "
- "Workflow count: {{ workflows.json.total }}"
- "Template count: {{ templates.json.count }}"
- "JST count: {{ transformations.json.total }}"
- "JSON form count: {{ jsonforms.json | length }}"
- "Job count: {{ jobs.json.metadata.total }}"
- "Paused job count: {{ paused_job_count }}"
- "Errored job count: {{ errored_job_count }}"
- "Task count: {{ active_tasks.json.metadata.total }}"
- "Manual Task Count: {{ manual_task_count }}"
3 changes: 3 additions & 0 deletions roles/fakenos/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fakenos_venv_path: /opt/automation-gateway/venv
fakenos_workdir: /opt/automation-gateway/fakenos
fakenos_iag_inventory_path: /opt/automation-gateway/ansible/inventory/fakenos.yaml
52 changes: 52 additions & 0 deletions roles/fakenos/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
- name: Install Fakenos
ansible.builtin.pip:
name: fakenos
state: present
virtualenv: "{{ fakenos_venv_path }}"

- name: Create Fakenos working directory
ansible.builtin.file:
name: "{{ fakenos_workdir }}"
state: directory
mode: '0775'
owner: itential
group: itential

- name: Generate Fakenos inventory
ansible.builtin.template:
src: fakenos_inventory.j2
dest: "{{ fakenos_workdir }}/inventory.yaml"
mode: '0644'
owner: itential
group: itential

- name: Get running Fakenos PIDs
ansible.builtin.shell: |
set -o pipefail
ps -ef | grep -v grep | grep -w fakenos | awk '{print $2}'
check_mode: false
changed_when: false
failed_when: false
register: fakenos_pids

- name: Kill existing Fakenos processes
ansible.builtin.command: "kill {{ item }}"
loop: "{{ fakenos_pids.stdout_lines }}"
when: fakenos_pids.stdout_lines | length > 0
changed_when: false

- name: Start Fakenos
ansible.builtin.shell: >
nohup {{ fakenos_venv_path }}/bin/python3
{{ fakenos_venv_path }}/bin/fakenos
--inventory {{ fakenos_workdir }}/inventory.yaml
> {{ fakenos_workdir }}/fakenos.out 2>&1 &
changed_when: false

- name: Generate Fakenos Inventory in IAG
ansible.builtin.template:
src: iag_fakenos_inventory.j2
dest: "{{ fakenos_iag_inventory_path }}"
mode: '0644'
owner: itential
group: itential
12 changes: 12 additions & 0 deletions roles/fakenos/templates/fakenos_inventory.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
hosts:
{% set ns = namespace(port=starting_port | default(6000)) %}
{% for key, device in fakenos_devices.items() %}
{% for i in range(1, device.count + 1) %}
mock-{{ key }}-{{ i }}:
username: "admin"
password: "admin"
platform: "{{ key }}"
port: {{ ns.port }}
{% set ns.port = ns.port + 1 %}
{% endfor %}
{% endfor %}
18 changes: 18 additions & 0 deletions roles/fakenos/templates/iag_fakenos_inventory.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
all:
children:
mock-devices:
hosts:
{% set ns = namespace(port=starting_port | default(6000)) %}
{% for key, device in fakenos_devices.items() %}
{% set network_os = device.vendor ~ '.' ~ device.platform ~ '.' ~ device.platform %}
{% for i in range(1, device.count + 1) %}
mock-{{ key }}-{{ i }}:
ansible_connection: network_cli
ansible_network_os: {{ network_os }}
ansible_host: 127.0.0.1
ansible_port: {{ ns.port }}
ansible_user: admin
ansible_password: admin
{% set ns.port = ns.port + 1 %}
{% endfor %}
{% endfor %}