-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add monitoring #36
base: main
Are you sure you want to change the base?
Add monitoring #36
Conversation
Signed-off-by: Dawid Lesiak <[email protected]>
Signed-off-by: Dawid Lesiak <[email protected]>
for more information, see https://pre-commit.ci
Signed-off-by: Dawid Lesiak <[email protected]>
c925200
to
8f0ad67
Compare
/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 #) |
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
## Create the item in Zabbix | ||
> | ||
> Item is a tool that gathers data from device, system or external script | ||
2. Navigate to **Configuration** > **Hosts**. |
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.
> It's likely that the last used tab is overwriting session data. | ||
|
||
## Create the item in Zabbix | ||
> |
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.
> |
[list of macros](https://www.zabbix.com/documentation/current/en/manual/appendix/macros/supported_by_location#host-inventory) | ||
|
||
## Create the trigger | ||
> |
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.
> |
|
||
## Create the trigger | ||
> | ||
> Trigger is a rule that watches for specific events, like high CPU usage. |
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
+ 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 |
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
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'. |
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
## Testing | ||
|
||
4. Test manually. | ||
- login as **zabbix** user and go to the script location. |
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
done < "$stolen" | ||
|
||
deactivate | ||
|
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.
remove empty line
if grep -qw "$ip" "$fail"; then | ||
echo 0 | ||
elif grep -qw "$ip" "$used"; then | ||
echo 1 |
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.
use consistent indentation
@@ -0,0 +1,15 @@ | |||
#!/bin/bash |
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.
do we actually use flash_read.sh and flash_write.sh files in monitoring process?
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.
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.
check_snipeit() { | ||
ip=$1 | ||
if [[ "$ip" =~ [0-9] ]]; then | ||
if osfv_cli snipeit list_used | grep -qw "$ip"; then |
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 is probably not needed, see below.
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" |
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.
Simply try to check out. If platform is used, you will simply get an arror:
Error checking out asset 52
Response data: {'status': 'error', 'messages': 'That asset is not available for checkout!', 'payload': {'asset': '00052'}}
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" |
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.
what is the purpose of this file? Can you briefly document each of them as a comment above?
output_used="/usr/lib/zabbix/externalscripts/output_used.txt" | ||
stolen="/usr/lib/zabbix/externalscripts/stolen.txt" | ||
|
||
> "$output_used" |
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.
When and where do you clear those files? Why not do it here at the beginning of the script?
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.
i used redirects to clear the file out of habbit, already changed them to rm
> "$output_used"
> "$output_pass"
> "$output_fail"
> "$stolen"
|
||
source /usr/lib/zabbix/externalscripts/venv/bin/activate | ||
|
||
input_file="/usr/lib/zabbix/externalscripts/macros.txt" |
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.
What is this file, and what it contains?
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.
$input_file
in this case macros.txt
contains list of IPs to use
I explained it in new commit
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 ???
ip=$1 | ||
if [[ "$ip" =~ [0-9] ]]; then | ||
if osfv_cli snipeit list_used | grep -qw "$ip"; then | ||
return 0 # IP is checked out |
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 logic seems reversed. When device is taken, I would treat it as some form of error. And we return 0 on sucess, and non-zero on error.
else | ||
osfv_cli snipeit check_out --rte_ip "$ip" | ||
echo "$ip" >> "$stolen" | ||
return 1 # IP not checked out |
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.
Return 0 on success
return 1 # IP not checked out | ||
fi | ||
else | ||
return 1 # IP contains no numbers |
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.
Return non-zero on error. ideally, different error code for different type of error (not 1 in two places).
fi | ||
done < "$input_file" | ||
|
||
while IFS= read -r ip || [ -n "$ip" ]; do |
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.
Was it added just recently, and should fix the devices being reserved on robot for too long?
# echo "$ip" >> "$output_used" | ||
else | ||
echo "$ip not found in snipeit list_used, probing flash..." | ||
probe_flash "$ip" |
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.
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.
Signed-off-by: Dawid Lesiak <[email protected]>
Signed-off-by: Dawid Lesiak <[email protected]>
No description provided.