-
Notifications
You must be signed in to change notification settings - Fork 3
Added role for fakenos. Also updated metrics to use custome modules #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | ||
steven-schattenberg-itential marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 %} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.