-
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
Changes from all 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,84 @@ | ||
# 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 | ||
|
||
```C | ||
/usr/lib/zabbix/externalscripts | ||
``` | ||
|
||
> 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 | ||
|
||
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. | ||
|
||
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 | ||
|
||
1. 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 commentThe reason will be displayed to describe this comment to others. Learn more. please indent |
||
- run your script as zabbix. | ||
|
||
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**. | ||
|
||
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 | ||
|
||
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**. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# 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 | ||
``` | ||
|
||
2. Create Crontab job. | ||
|
||
```C | ||
crontab -e | ||
``` | ||
|
||
```C | ||
crontab -e | ||
``` | ||
|
||
> 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**. | ||
2. 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. | ||
|
||
2. 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** | ||
- 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** | ||
- 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 | ||
|
||
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**. | ||
|
||
2. 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, `./script.sh '192.168.10.0'`. | ||
|
||
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. | ||
- Press **Get value and test**. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/bash | ||
#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" | ||
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? 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.
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 ??? |
||
|
||
#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" | ||
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? |
||
|
||
rm "$output_used" | ||
rm "$output_pass" | ||
rm "$output_fail" | ||
rm "$stolen" | ||
|
||
check_snipeit() { | ||
ip=$1 | ||
if [[ "$ip" =~ [0-9] ]]; then | ||
if osfv_cli snipeit check_out --rte_ip "$ip" | grep -qw "successfully checked out."; then | ||
return 0 #ip successfully checked out | ||
else | ||
return 3 #failed to check out | ||
fi | ||
else | ||
return 2 # 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" | ||
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 successfully checked out, probing flash..." | ||
probe_flash "$ip" | ||
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. |
||
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" | ||
deactivate |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
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? 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. |
||
|
||
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" "$output_fail"; then | ||
echo 2 | ||
elif grep -qw "$ip" "$output_used"; then | ||
echo 1 | ||
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" "$output_pass"; then | ||
echo 0 | ||
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 0 | ||
else | ||
# echo "Macro '$macro' already exists in the file." | ||
echo 2 | ||
fi | ||
done |
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