-
Notifications
You must be signed in to change notification settings - Fork 0
Add monitoring #36
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
base: main
Are you sure you want to change the base?
Add monitoring #36
Changes from 4 commits
a355b65
767286e
e61f02a
8f0ad67
80eb3af
ebb2e54
6ae7d25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,81 @@ | ||||
| # 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 | ||||
| > | ||||
|
||||
| > |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This numbering makes no sense. Either use 1 everywhere (and let the markdown renderer handle it), or use incremental numbering in each section manually.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| > |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add empty line below
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add empty line above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please indent
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add empty line above
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this file, and what it contains?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dawidlesiak ??? |
||
|
|
||
| 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" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the purpose of this file? Can you briefly document each of them as a comment above? |
||
|
|
||
| > "$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" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about simply invoking check_in below? After we call probe_flash, we no longer need the device to be checked out, right? This makes another loop and stolen.txt not needed. |
||
| fi | ||
| done < "$input_file" | ||
|
|
||
| while IFS= read -r ip || [ -n "$ip" ]; do | ||
|
||
| osfv_cli snipeit check_in --rte_ip "$ip" | ||
| done < "$stolen" | ||
|
|
||
| deactivate | ||
|
|
||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #!/bin/bash | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we actually use flash_read.sh and flash_write.sh files in monitoring process?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, flash_read.sh and flash_write.sh are executed by Zabbix and are separated into two files for ease of use with zabbix. Meanwhile flash_probe.sh is executed by a crontab or another automation tool due to Zabbix's timeout limitations. |
||
|
|
||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use consistent indentation |
||
| elif grep -qw "$ip" "$pass"; then | ||
| echo 2 | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dawidlesiak Please use pre-commit locally. See failures: https://results.pre-commit.ci/run/github/649846685/1716814016.AtAIM8RRQYqQuw086aFAZQ