From a355b65255ff71cb058273af0bc70df1cbac3a5d Mon Sep 17 00:00:00 2001 From: Dawid Lesiak Date: Fri, 10 May 2024 14:31:54 +0200 Subject: [PATCH 1/7] osfv_cli: add zabbix monitoring and custom scripts documentation Signed-off-by: Dawid Lesiak --- osfv_cli/monitoring/zabbix/External_Check.md | 77 ++++++++++++++++++++ osfv_cli/monitoring/zabbix/flash_probe.sh | 20 +++++ 2 files changed, 97 insertions(+) create mode 100644 osfv_cli/monitoring/zabbix/External_Check.md create mode 100644 osfv_cli/monitoring/zabbix/flash_probe.sh diff --git a/osfv_cli/monitoring/zabbix/External_Check.md b/osfv_cli/monitoring/zabbix/External_Check.md new file mode 100644 index 0000000..2651f78 --- /dev/null +++ b/osfv_cli/monitoring/zabbix/External_Check.md @@ -0,0 +1,77 @@ +# External Check Zabbix + +This is a brief guide on setting up external checks in Zabbix. +You can find example scripts in this folder. + +## Preparation +1. Make sure your script is in +``` +/usr/lib/zabbix/externalscripts +``` +> The default location of externalscripts can be changed in `/etc/zabbix/zabbix_server.conf` by editing `ExternalScripts=/usr/lib/zabbix/externalscripts` (make sure to remove #) + +**Ensure that you have only one tab open when creating anything in Zabbix (items/triggers/hosts).** +> It's likely that the last used tab is overwriting session data. + + + +## Create the item in Zabbix +> Item is a tool that gathers data from device, system or external script +2. Navigate to **Configuration** > **Hosts**. +2. Go to the **Items** next to the host you want to monitor. +2. Click **Create item** in top right. + - Change Type to **External check**. + - As key use your script name together with desired **Macro**, for example `script.sh[{HOST.IP}]`. + + You can combine multiple Macros `script.sh[{HOST.DESCRIPTION},{HOST.ID},{HOST.CONN}]`. + + +[list of macros](https://www.zabbix.com/documentation/current/en/manual/appendix/macros/supported_by_location#host-inventory) + +## Create the trigger +> Trigger is a rule that watches for specific events, like high CPU usage. +3. Navigate to **Configuration** > **Hosts**. +3. Go to the **Triggers** next to the host with the item you want to monitor. +3. Click **Create trigger** in top right. + - Severity: Select as needed. + - Expression: press Add + + Item: Select the item for which you want to create a trigger. + + Function: Defines how your trigger will be activated. + + Result: Actual rule of activation. +> If your script returns numeric values directly and/or you don't won't to calculate the average result, simply use `last()` function + +## Testing +4. Test manually. +- login as **zabbix** user and go to the script location. +- run your script as zabbix. +> You can directly incorporate information from Zabbix macros into your command, such as ./script.sh '192.168.10.0'. + +4. Test in zabbix web interface. +- Go to your item location. +- If you are using external checks, **Test** option should be available. + + Check if you Macros give proper data to your script. + + Press **Get value and test**. + +4. Common problems. +- Timeout: you can change (not VM)Timeout(and TrapperTimeout if needed) settings in /etc/zabbix/zabbix_server.conf +- Make sure all necesery files and commands are accessible for zabbix user. +- If you find something else, please update the file. + +## Templates +5. Navigate to **Configuration** > **Templates**. +5. Click **Create template** in top right. + - Specify the name, group and other information if needed. +5. Add **items**, **trigger** and **macros** if needed. +5. Link the template to **Hosts** + 5. Mass update + - Go to **Hosts**. + - Check the boxes next to the desired hosts. + - Scroll to the bottom and click **Mass update**. + + Select **Link templates**. + + Choose **Link**. + + Enter your template name. + + Press **Update**. + + 5. Single update + - Open desired **Host**. + - Add your Template under Templates. + - Press **Update**. diff --git a/osfv_cli/monitoring/zabbix/flash_probe.sh b/osfv_cli/monitoring/zabbix/flash_probe.sh new file mode 100644 index 0000000..99abb37 --- /dev/null +++ b/osfv_cli/monitoring/zabbix/flash_probe.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +#\/\/\/Change source location\/\/\/ +source /usr/lib/zabbix/externalscripts/venv/bin/activate +#/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ + +output1=$(osfv_cli snipeit list_used | grep "$1") + +if [[ -n "$output1" ]]; then + echo 3 # TAKEN +else + output2=$(osfv_cli rte --rte_ip "$1" flash probe) + if [[ $output2 == *" flash chip "* ]]; then + echo 1 # Success + else + echo 0 # Failure + fi +fi + +deactivate From 767286e791b049e0fa89d9f0b0bb7cd0dc182985 Mon Sep 17 00:00:00 2001 From: Dawid Lesiak Date: Fri, 17 May 2024 17:58:57 +0200 Subject: [PATCH 2/7] osfv-scripts/osfv_cli/monitoring: update and change script location Signed-off-by: Dawid Lesiak --- .../external_flash_probe/flash_probe.sh | 59 +++++++++++++++++++ .../zabbix/external_flash_probe/flash_read.sh | 15 +++++ .../external_flash_probe/flash_write.sh | 24 ++++++++ osfv_cli/monitoring/zabbix/flash_probe.sh | 20 ------- 4 files changed, 98 insertions(+), 20 deletions(-) create mode 100644 osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.sh create mode 100644 osfv_cli/monitoring/zabbix/external_flash_probe/flash_read.sh create mode 100644 osfv_cli/monitoring/zabbix/external_flash_probe/flash_write.sh delete mode 100644 osfv_cli/monitoring/zabbix/flash_probe.sh diff --git a/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.sh b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.sh new file mode 100644 index 0000000..a4c005f --- /dev/null +++ b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +cd /usr/lib/zabbix/externalscripts/ + +source /usr/lib/zabbix/externalscripts/venv/bin/activate + +input_file="/usr/lib/zabbix/externalscripts/macros.txt" + +output_pass="/usr/lib/zabbix/externalscripts/output_pass.txt" +output_fail="/usr/lib/zabbix/externalscripts/output_fail.txt" +output_used="/usr/lib/zabbix/externalscripts/output_used.txt" +stolen="/usr/lib/zabbix/externalscripts/stolen.txt" + +> "$output_used" +> "$output_pass" +> "$output_fail" +> "$stolen" + +check_snipeit() { + ip=$1 + if [[ "$ip" =~ [0-9] ]]; then + if osfv_cli snipeit list_used | grep -qw "$ip"; then + return 0 # IP is checked out + else + osfv_cli snipeit check_out --rte_ip "$ip" + echo "$ip" >> "$stolen" + return 1 # IP not checked out + fi + else + return 1 # IP contains no numbers + fi +} + +probe_flash() { + ip=$1 + output_flash=$(osfv_cli rte --rte_ip "$ip" flash probe) + if echo "$output_flash" | grep -qE 'Found .* flash chip ".*" \(.*\) on .*\.'; then + echo "$ip" >> "$output_pass" + else + echo "$ip" >> "$output_fail" + fi +} + +while IFS= read -r ip || [ -n "$ip" ]; do + if check_snipeit "$ip"; then + echo "$ip found in snipeit list_used" + echo "$ip" >> "$output_used" + else + echo "$ip not found in snipeit list_used, probing flash..." + probe_flash "$ip" + fi +done < "$input_file" + +while IFS= read -r ip || [ -n "$ip" ]; do + osfv_cli snipeit check_in --rte_ip "$ip" +done < "$stolen" + +deactivate + diff --git a/osfv_cli/monitoring/zabbix/external_flash_probe/flash_read.sh b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_read.sh new file mode 100644 index 0000000..3042134 --- /dev/null +++ b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_read.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +fail="/usr/lib/zabbix/externalscripts/output_fail.txt" +used="/usr/lib/zabbix/externalscripts/output_used.txt" +pass="/usr/lib/zabbix/externalscripts/output_pass.txt" + +ip=$1 + +if grep -qw "$ip" "$fail"; then + echo 0 +elif grep -qw "$ip" "$used"; then + echo 1 +elif grep -qw "$ip" "$pass"; then + echo 2 +fi diff --git a/osfv_cli/monitoring/zabbix/external_flash_probe/flash_write.sh b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_write.sh new file mode 100644 index 0000000..a430ace --- /dev/null +++ b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_write.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +output_file="/usr/lib/zabbix/externalscripts/macros.txt" + +touch "$output_file" + +if [ -z $1 ]; then +# echo "No macro provided." + exit 1 +fi + +macro_exists() { + grep -qF "$1" "$output_file" +} + +for macro in "$@"; do + if ! macro_exists "$macro"; then + echo "$macro" >> "$output_file" + echo 1 + else +# echo "Macro '$macro' already exists in the file." + echo 0 + fi +done diff --git a/osfv_cli/monitoring/zabbix/flash_probe.sh b/osfv_cli/monitoring/zabbix/flash_probe.sh deleted file mode 100644 index 99abb37..0000000 --- a/osfv_cli/monitoring/zabbix/flash_probe.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -#\/\/\/Change source location\/\/\/ -source /usr/lib/zabbix/externalscripts/venv/bin/activate -#/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ - -output1=$(osfv_cli snipeit list_used | grep "$1") - -if [[ -n "$output1" ]]; then - echo 3 # TAKEN -else - output2=$(osfv_cli rte --rte_ip "$1" flash probe) - if [[ $output2 == *" flash chip "* ]]; then - echo 1 # Success - else - echo 0 # Failure - fi -fi - -deactivate From e61f02af29619518b9206f50dbffce80b1fbe307 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 12:52:59 +0000 Subject: [PATCH 3/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- osfv_cli/monitoring/zabbix/External_Check.md | 66 +++++++++++--------- osfv_cli/osfv_cli/osfv_cli.py | 1 + 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/osfv_cli/monitoring/zabbix/External_Check.md b/osfv_cli/monitoring/zabbix/External_Check.md index 2651f78..67b6557 100644 --- a/osfv_cli/monitoring/zabbix/External_Check.md +++ b/osfv_cli/monitoring/zabbix/External_Check.md @@ -4,52 +4,55 @@ This is a brief guide on setting up external checks in Zabbix. You can find example scripts in this folder. ## Preparation -1. Make sure your script is in + +1. Make sure your script is in + ``` -/usr/lib/zabbix/externalscripts +/usr/lib/zabbix/externalscripts ``` + > The default location of externalscripts can be changed in `/etc/zabbix/zabbix_server.conf` by editing `ExternalScripts=/usr/lib/zabbix/externalscripts` (make sure to remove #) **Ensure that you have only one tab open when creating anything in Zabbix (items/triggers/hosts).** > It's likely that the last used tab is overwriting session data. - - ## Create the item in Zabbix +> > Item is a tool that gathers data from device, system or external script 2. Navigate to **Configuration** > **Hosts**. 2. Go to the **Items** next to the host you want to monitor. 2. Click **Create item** in top right. - - Change Type to **External check**. - - As key use your script name together with desired **Macro**, for example `script.sh[{HOST.IP}]`. - + You can combine multiple Macros `script.sh[{HOST.DESCRIPTION},{HOST.ID},{HOST.CONN}]`. - + - Change Type to **External check**. + - As key use your script name together with desired **Macro**, for example `script.sh[{HOST.IP}]`. + + You can combine multiple Macros `script.sh[{HOST.DESCRIPTION},{HOST.ID},{HOST.CONN}]`. [list of macros](https://www.zabbix.com/documentation/current/en/manual/appendix/macros/supported_by_location#host-inventory) ## Create the trigger +> > Trigger is a rule that watches for specific events, like high CPU usage. 3. Navigate to **Configuration** > **Hosts**. 3. Go to the **Triggers** next to the host with the item you want to monitor. 3. Click **Create trigger** in top right. - - Severity: Select as needed. - - Expression: press Add - + Item: Select the item for which you want to create a trigger. - + Function: Defines how your trigger will be activated. - + Result: Actual rule of activation. + - Severity: Select as needed. + - Expression: press Add + + Item: Select the item for which you want to create a trigger. + + Function: Defines how your trigger will be activated. + + Result: Actual rule of activation. > If your script returns numeric values directly and/or you don't won't to calculate the average result, simply use `last()` function ## Testing + 4. Test manually. - login as **zabbix** user and go to the script location. - run your script as zabbix. > You can directly incorporate information from Zabbix macros into your command, such as ./script.sh '192.168.10.0'. 4. Test in zabbix web interface. -- Go to your item location. +- Go to your item location. - If you are using external checks, **Test** option should be available. - + Check if you Macros give proper data to your script. - + Press **Get value and test**. + - Check if you Macros give proper data to your script. + - Press **Get value and test**. 4. Common problems. - Timeout: you can change (not VM)Timeout(and TrapperTimeout if needed) settings in /etc/zabbix/zabbix_server.conf @@ -57,21 +60,22 @@ You can find example scripts in this folder. - If you find something else, please update the file. ## Templates -5. Navigate to **Configuration** > **Templates**. + +5. Navigate to **Configuration** > **Templates**. 5. Click **Create template** in top right. - - Specify the name, group and other information if needed. + - Specify the name, group and other information if needed. 5. Add **items**, **trigger** and **macros** if needed. 5. Link the template to **Hosts** - 5. Mass update - - Go to **Hosts**. - - Check the boxes next to the desired hosts. - - Scroll to the bottom and click **Mass update**. - + Select **Link templates**. - + Choose **Link**. - + Enter your template name. - + Press **Update**. - - 5. Single update - - Open desired **Host**. - - Add your Template under Templates. - - Press **Update**. + 5. Mass update + - Go to **Hosts**. + - Check the boxes next to the desired hosts. + - Scroll to the bottom and click **Mass update**. + + Select **Link templates**. + + Choose **Link**. + + Enter your template name. + + Press **Update**. + + 5. Single update + + Open desired **Host**. + + Add your Template under Templates. + + Press **Update**. diff --git a/osfv_cli/osfv_cli/osfv_cli.py b/osfv_cli/osfv_cli/osfv_cli.py index 85fac19..feab90c 100755 --- a/osfv_cli/osfv_cli/osfv_cli.py +++ b/osfv_cli/osfv_cli/osfv_cli.py @@ -72,6 +72,7 @@ def list_my_assets(snipeit_api, args): for asset in my_assets: print_asset_details(asset) + # List unused assets def list_unused_assets(snipeit_api, args): all_assets = snipeit_api.get_all_assets() From 8f0ad67a36f56de51c354d5943b16bfd38deee78 Mon Sep 17 00:00:00 2001 From: Dawid Lesiak Date: Mon, 20 May 2024 11:57:53 +0200 Subject: [PATCH 4/7] osfv_cli/monitoring/zabbix: script cleanup Signed-off-by: Dawid Lesiak --- osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.sh b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.sh index a4c005f..94e69af 100644 --- a/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.sh +++ b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.sh @@ -44,7 +44,7 @@ probe_flash() { while IFS= read -r ip || [ -n "$ip" ]; do if check_snipeit "$ip"; then echo "$ip found in snipeit list_used" - echo "$ip" >> "$output_used" +# echo "$ip" >> "$output_used" else echo "$ip not found in snipeit list_used, probing flash..." probe_flash "$ip" From 80eb3afcae0519539fc2f21681f92769eacf5c07 Mon Sep 17 00:00:00 2001 From: Dawid Lesiak Date: Tue, 28 May 2024 18:09:35 +0200 Subject: [PATCH 5/7] osfv-scripts/osfv_cli/monitoring: update script Signed-off-by: Dawid Lesiak --- osfv_cli/monitoring/zabbix/External_Check.md | 93 ++++++++++--------- .../external_flash_probe/flash_probe.md | 76 +++++++++++++++ .../external_flash_probe/flash_probe.sh | 46 ++++----- .../zabbix/external_flash_probe/flash_read.sh | 16 ++-- .../external_flash_probe/flash_write.sh | 4 +- 5 files changed, 158 insertions(+), 77 deletions(-) create mode 100644 osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.md diff --git a/osfv_cli/monitoring/zabbix/External_Check.md b/osfv_cli/monitoring/zabbix/External_Check.md index 67b6557..65d6ece 100644 --- a/osfv_cli/monitoring/zabbix/External_Check.md +++ b/osfv_cli/monitoring/zabbix/External_Check.md @@ -7,75 +7,78 @@ You can find example scripts in this folder. 1. Make sure your script is in -``` +```C /usr/lib/zabbix/externalscripts ``` -> The default location of externalscripts can be changed in `/etc/zabbix/zabbix_server.conf` by editing `ExternalScripts=/usr/lib/zabbix/externalscripts` (make sure to remove #) +> The default location can be changed in `/etc/zabbix/zabbix_server.conf` +> by editing `ExternalScripts=/usr/lib/zabbix/externalscripts` **Ensure that you have only one tab open when creating anything in Zabbix (items/triggers/hosts).** + > It's likely that the last used tab is overwriting session data. ## Create the item in Zabbix -> + > Item is a tool that gathers data from device, system or external script -2. Navigate to **Configuration** > **Hosts**. -2. Go to the **Items** next to the host you want to monitor. -2. Click **Create item** in top right. - - Change Type to **External check**. - - As key use your script name together with desired **Macro**, for example `script.sh[{HOST.IP}]`. - + You can combine multiple Macros `script.sh[{HOST.DESCRIPTION},{HOST.ID},{HOST.CONN}]`. -[list of macros](https://www.zabbix.com/documentation/current/en/manual/appendix/macros/supported_by_location#host-inventory) +1. Navigate to **Configuration** > **Hosts**. +1. Go to the **Items** next to the host you want to monitor. +1. Click **Create item** in top right. +- Change Type to **External check**. +- As key use your script name together with desired **Macro**, for example `script.sh[{HOST.IP}]`. + +> [External Checks](https://www.zabbix.com/documentation/current/en/manual/config/items/itemtypes/external) +> [List of macros](https://www.zabbix.com/documentation/current/en/manual/appendix/macros/supported_by_location#host-inventory) ## Create the trigger -> + > Trigger is a rule that watches for specific events, like high CPU usage. -3. Navigate to **Configuration** > **Hosts**. -3. Go to the **Triggers** next to the host with the item you want to monitor. -3. Click **Create trigger** in top right. - - Severity: Select as needed. - - Expression: press Add - + Item: Select the item for which you want to create a trigger. - + Function: Defines how your trigger will be activated. - + Result: Actual rule of activation. -> If your script returns numeric values directly and/or you don't won't to calculate the average result, simply use `last()` function + +1. Navigate to **Configuration** > **Hosts**. +1. Go to the **Triggers** next to the host with the item you want to monitor. +1. Click **Create trigger** in top right. +- Severity: Select as needed. +- Expression: press Add + + Item: Select the item for which you want to create a trigger. + + Function: Defines how your trigger will be activated. + + Result: Actual rule of activation. ## Testing -4. Test manually. +1. Test manually. - login as **zabbix** user and go to the script location. - run your script as zabbix. -> You can directly incorporate information from Zabbix macros into your command, such as ./script.sh '192.168.10.0'. -4. Test in zabbix web interface. +1. Test in zabbix web interface. - Go to your item location. - If you are using external checks, **Test** option should be available. - - Check if you Macros give proper data to your script. - - Press **Get value and test**. +- Check if you Macros give proper data to your script. +- Press **Get value and test**. -4. Common problems. -- Timeout: you can change (not VM)Timeout(and TrapperTimeout if needed) settings in /etc/zabbix/zabbix_server.conf +1. Common problems. +- Timeout: you can change Timeout value in `/etc/zabbix/zabbix_server.conf` - Make sure all necesery files and commands are accessible for zabbix user. - If you find something else, please update the file. ## Templates -5. Navigate to **Configuration** > **Templates**. -5. Click **Create template** in top right. - - Specify the name, group and other information if needed. -5. Add **items**, **trigger** and **macros** if needed. -5. Link the template to **Hosts** - 5. Mass update - - Go to **Hosts**. - - Check the boxes next to the desired hosts. - - Scroll to the bottom and click **Mass update**. - + Select **Link templates**. - + Choose **Link**. - + Enter your template name. - + Press **Update**. - - 5. Single update - + Open desired **Host**. - + Add your Template under Templates. - + Press **Update**. +1. Navigate to **Configuration** > **Templates**. +1. Click **Create template** in top right. +- Specify the name, group and other information if needed. +1. Add **items**, **trigger** and **macros** if needed. +1. Link the template to **Hosts** +1. Mass update +- Go to **Hosts**. +- Check the boxes next to the desired hosts. +- Scroll to the bottom and click **Mass update**. + + Select **Link templates**. + + Choose **Link**. + + Enter your template name. + + Press **Update**. + +1. Single update +- Go to **Hosts**. + + Open desired **Host**. + + Add your Template under Templates. + + Press **Update**. diff --git a/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.md b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.md new file mode 100644 index 0000000..b5fb917 --- /dev/null +++ b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.md @@ -0,0 +1,76 @@ +# How To implement This script? + +1. Move `flash_probe.sh`, `flash_read.sh`, `flash_write.sh` to external script location. + +- By default it is: + +```C +/usr/lib/zabbix/externalscripts +``` + +1. Create Crontab job. + +> The script runs every 30 minutes between 4:00 AM and 10:00 PM, Monday to Friday. + +```C +*/30 4-22 * * 1-5 /usr/lib/zabbix/externalscripts/flash_probe.sh +``` + +## Create Template + +1. Navigate to **Configuration** > **Templates**. +1. Click **Create template** in top right. +- Specify the name, group and other information if needed. + +## Create Items + +1. First item. +- Change type to **External check**. +- Set Key to `flash_read.sh[{HOST.IP}]`. +- Set update interval to 5m. + +1. Second item. +- Change type to **External check**. +- Set Key to `flash_write.sh[{HOST.IP}]`. +- Set **update interval** to **5m**. + +## Create Triggers + +1. First trigger. +- Severity: **High** +- Expression: `max(/Flash probe/flash_read.sh[{HOST.IP}],15m)=2` + +1. Second trigger. +- Severity: **Information** +- Expression: `max(/Flash probe/flash_read.sh[{HOST.IP}],25m)=1` + +## Link Hosts to the template + +1. Mass update +- Go to **Hosts**. +- Check the boxes next to the desired hosts. +- Scroll to the bottom and click **Mass update**. + + Select **Link templates**. + + Choose **Link**. + + Enter your template name. + + Press **Update**. + +1. Single update. +- Go to **Hosts**. + + Open desired **Host**. + + Add your Template under Templates. + + Press **Update**. + +## Testing + +1. Test manually. +- login as **zabbix** user and go to the script location. +- run your script as zabbix. + +> You can incorporate Zabbix macros into your command, like ./script.sh '192.168.10.0'. + +1. Test in zabbix web interface. +- Go to your item location. +- If you are using external checks, **Test** option should be available. +- Check if you Macros give proper data to your script. +- Press **Get value and test**. diff --git a/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.sh b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.sh index 94e69af..a2dad02 100644 --- a/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.sh +++ b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.sh @@ -1,33 +1,36 @@ #!/bin/bash - -cd /usr/lib/zabbix/externalscripts/ +#Output files location +Cd /usr/lib/zabbix/externalscripts/ source /usr/lib/zabbix/externalscripts/venv/bin/activate +#File with IPs to check -created by flash_write.sh input_file="/usr/lib/zabbix/externalscripts/macros.txt" +#The file where the IPs that passed 'flash probe' without issues are saved. output_pass="/usr/lib/zabbix/externalscripts/output_pass.txt" +#The file where the IPs that did not pass 'flash probe' are saved. output_fail="/usr/lib/zabbix/externalscripts/output_fail.txt" +#The file where the IPs that are currently in use are saved. output_used="/usr/lib/zabbix/externalscripts/output_used.txt" +#The file where the IPs that are currently stolen bo this script are saved. stolen="/usr/lib/zabbix/externalscripts/stolen.txt" -> "$output_used" -> "$output_pass" -> "$output_fail" -> "$stolen" +rm "$output_used" +rm "$output_pass" +rm "$output_fail" +rm "$stolen" check_snipeit() { ip=$1 if [[ "$ip" =~ [0-9] ]]; then - if osfv_cli snipeit list_used | grep -qw "$ip"; then - return 0 # IP is checked out + if osfv_cli snipeit check_out --rte_ip "$ip" | grep -qw "successfully checked out."; then + return 0 #ip successfully checked out else - osfv_cli snipeit check_out --rte_ip "$ip" - echo "$ip" >> "$stolen" - return 1 # IP not checked out + return 3 #failed to check out fi else - return 1 # IP contains no numbers + return 2 # IP contains no numbers fi } @@ -36,24 +39,23 @@ probe_flash() { output_flash=$(osfv_cli rte --rte_ip "$ip" flash probe) if echo "$output_flash" | grep -qE 'Found .* flash chip ".*" \(.*\) on .*\.'; then echo "$ip" >> "$output_pass" + return 0 else echo "$ip" >> "$output_fail" + return 1 fi } while IFS= read -r ip || [ -n "$ip" ]; do if check_snipeit "$ip"; then - echo "$ip found in snipeit list_used" -# echo "$ip" >> "$output_used" - else - echo "$ip not found in snipeit list_used, probing flash..." + echo "$ip successfully checked out, probing flash..." probe_flash "$ip" + osfv_cli snipeit check_in --rte_ip "$ip" + return 0 + else + echo "Failed to checkout $ip ._." + echo "$ip" >> "$output_used" + return 3 #Failed to check out IP fi done < "$input_file" - -while IFS= read -r ip || [ -n "$ip" ]; do - osfv_cli snipeit check_in --rte_ip "$ip" -done < "$stolen" - deactivate - diff --git a/osfv_cli/monitoring/zabbix/external_flash_probe/flash_read.sh b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_read.sh index 3042134..9dde534 100644 --- a/osfv_cli/monitoring/zabbix/external_flash_probe/flash_read.sh +++ b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_read.sh @@ -1,15 +1,15 @@ #!/bin/bash -fail="/usr/lib/zabbix/externalscripts/output_fail.txt" -used="/usr/lib/zabbix/externalscripts/output_used.txt" -pass="/usr/lib/zabbix/externalscripts/output_pass.txt" +output_fail="/usr/lib/zabbix/externalscripts/output_fail.txt" +output_used="/usr/lib/zabbix/externalscripts/output_used.txt" +output_pass="/usr/lib/zabbix/externalscripts/output_pass.txt" ip=$1 -if grep -qw "$ip" "$fail"; then - echo 0 -elif grep -qw "$ip" "$used"; then +if grep -qw "$ip" "$output_fail"; then + echo 2 +elif grep -qw "$ip" "$output_used"; then echo 1 -elif grep -qw "$ip" "$pass"; then - echo 2 +elif grep -qw "$ip" "$output_pass"; then + echo 0 fi diff --git a/osfv_cli/monitoring/zabbix/external_flash_probe/flash_write.sh b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_write.sh index a430ace..0f29c9e 100644 --- a/osfv_cli/monitoring/zabbix/external_flash_probe/flash_write.sh +++ b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_write.sh @@ -16,9 +16,9 @@ macro_exists() { for macro in "$@"; do if ! macro_exists "$macro"; then echo "$macro" >> "$output_file" - echo 1 + echo 0 else # echo "Macro '$macro' already exists in the file." - echo 0 + echo 2 fi done From ebb2e547b59bfe902454f80ca262634b7505853d Mon Sep 17 00:00:00 2001 From: Dawid Lesiak <166387055+dawidlesiak@users.noreply.github.com> Date: Wed, 29 May 2024 14:08:43 +0200 Subject: [PATCH 6/7] osfv-scripts/osfv_cli/monitoring: update flash_probe.md --- .../zabbix/external_flash_probe/flash_probe.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.md b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.md index b5fb917..522beb1 100644 --- a/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.md +++ b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.md @@ -8,7 +8,11 @@ /usr/lib/zabbix/externalscripts ``` -1. Create Crontab job. +2. Create Crontab job. + +```C +crontab -e +``` > The script runs every 30 minutes between 4:00 AM and 10:00 PM, Monday to Friday. @@ -19,7 +23,7 @@ ## Create Template 1. Navigate to **Configuration** > **Templates**. -1. Click **Create template** in top right. +2. Click **Create template** in top right. - Specify the name, group and other information if needed. ## Create Items @@ -29,7 +33,7 @@ - Set Key to `flash_read.sh[{HOST.IP}]`. - Set update interval to 5m. -1. Second item. +2. Second item. - Change type to **External check**. - Set Key to `flash_write.sh[{HOST.IP}]`. - Set **update interval** to **5m**. @@ -40,7 +44,7 @@ - Severity: **High** - Expression: `max(/Flash probe/flash_read.sh[{HOST.IP}],15m)=2` -1. Second trigger. +2. Second trigger. - Severity: **Information** - Expression: `max(/Flash probe/flash_read.sh[{HOST.IP}],25m)=1` @@ -55,7 +59,7 @@ + Enter your template name. + Press **Update**. -1. Single update. +2. Single update. - Go to **Hosts**. + Open desired **Host**. + Add your Template under Templates. @@ -67,9 +71,9 @@ - login as **zabbix** user and go to the script location. - run your script as zabbix. -> You can incorporate Zabbix macros into your command, like ./script.sh '192.168.10.0'. +> You can incorporate Zabbix macros into your command, `./script.sh '192.168.10.0'`. -1. Test in zabbix web interface. +2. Test in zabbix web interface. - Go to your item location. - If you are using external checks, **Test** option should be available. - Check if you Macros give proper data to your script. From 6ae7d2594b72e6aba2eef7b4411b90582a2c4893 Mon Sep 17 00:00:00 2001 From: Dawid Lesiak <166387055+dawidlesiak@users.noreply.github.com> Date: Wed, 29 May 2024 14:08:43 +0200 Subject: [PATCH 7/7] osfv-scripts/osfv_cli/monitoring: update flash_probe.md Signed-off-by: Dawid Lesiak --- .../external_flash_probe/flash_probe.md | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.md b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.md index 522beb1..0ed6a2e 100644 --- a/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.md +++ b/osfv_cli/monitoring/zabbix/external_flash_probe/flash_probe.md @@ -14,6 +14,10 @@ crontab -e ``` +```C +crontab -e +``` + > The script runs every 30 minutes between 4:00 AM and 10:00 PM, Monday to Friday. ```C @@ -42,11 +46,24 @@ crontab -e 1. First trigger. - Severity: **High** -- Expression: `max(/Flash probe/flash_read.sh[{HOST.IP}],15m)=2` +- Name: Clip Fail +- Expression: + +```C +min(/Flash probe/flash_read_2zabbix.sh[{HOST.IP}],15m)=2 and +last(/Flash probe/flash_read_2zabbix.sh[{HOST.IP}])=2 +``` 2. Second trigger. - Severity: **Information** -- Expression: `max(/Flash probe/flash_read.sh[{HOST.IP}],25m)=1` +- Name: Platform checked out +- Expression: + +```C +max(/Flash probe/flash_read_2zabbix.sh[{HOST.IP}],15m)=1 and +min(/Flash probe/flash_read_2zabbix.sh[{HOST.IP}],15m)=1 and +last(/Flash probe/flash_read_2zabbix.sh[{HOST.IP}])=1 +``` ## Link Hosts to the template