Ajout des fichiers du projet

This commit is contained in:
Frogg 2026-05-15 20:40:46 +02:00
parent c9a3ab5e76
commit 2dc144d356
6 changed files with 531 additions and 0 deletions

View File

@ -1 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.0.0] - 2026/02/15
### Added
- added Zabbix 5.2, 6.0 & 7.0 compatibility

137
README.md
View File

@ -1 +1,138 @@
### Zabbix Template Module NFS version 1.0.0
Tested on Zabbix 4.4 to 7.0
# Introduction
Template for Zabbix to check nfs share availability using external script.
It can check:
* If NFS server is accepting request
* If NFS share are available
* The NFS server version
# Requirement
The script use the commands **showmount** & **rpcinfo** so it requires the Linux package **nfs-common**
To install it you can use the package manager of your distribution
Exemple
```bash
apt-get install nfs-common
```
By the way you may require sudoer rights to run the command.
On Linux NFS server you may need to install **rpcbind** service to get information from **rpcinfo** command
# Installation
## Content
The template installation require 3 files:
* `frogg_nfs_check.sh` Zabbix external script
* `zabbix_template.*` Zabbix template configuration
* `userparameter_frogg_nfs_check.conf` Zabbix shortcut for a clean call
## Introduction
The script will be launched by Zabbix server, testing if client nfs share is available using a script.
That mean Zabbix network must be able to see nfs sharing of the client on the network.
* All the files are installed on Zabbix server, none is required on the client.
* Your network must allow Zabbix server to see nfs share of the client
* First check your external script folder, in most of new version you can find it in `/usr/lib/zabbix/externalscripts`
You can find the ExternalScripts folder in your `/etc/zabbix/zabbix_server.conf` (default location)
```
### Option: ExternalScripts
# Full path to location of external scripts.
# Default depends on compilation options.
# To see the default path run command "zabbix_server --help".
#
# Mandatory: no
# Default:
# ExternalScripts=${datadir}/zabbix/externalscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
```
* For a cleaner script calling this template now use `userparameter` file, You can verify the path stored in your `/etc/zabbix/zabbix_agentd.conf` (default location)
```
### Option: Include
# You may include individual files or all files in a directory in the configuration file.
# Installing Zabbix will create include directory in /usr/local/etc, unless modified during the compile time.
#
# Mandatory: no
# Default:
# Include=
Include=/etc/zabbix/zabbix_agentd.d/*.conf
```
If `/etc/zabbix/zabbix_agentd.conf.d/` doesn't exist you can create it
## External script
### Scripts
Place the `frogg_nfs_check.sh` in `/usr/lib/zabbix/externalscripts`.
You will need to add execute permission on the script
```console
chmod +x frogg_nfs_check.sh
```
### User parameters
Add the `userparameter_frogg_nfs_check.conf` to `/etc/zabbix/zabbix_agentd.conf.d/` (default location)
### Testing the installation
You can run the command:
- To Test NFS version
```
./frogg_nfs_check.sh version <ip-of-server>
```
- To Test NFS share
```
./frogg_nfs_check.sh share <ip-of-server> "/nfsShare1,/nfsShare2,/nfsShare3"
```
## Template
Then you need to import the `zabbix_template.*` template configuration file in the Zabbix web interface in **Template** tab using the import button
# Host configuration
The template use 2 macros :
| MACRO | Description |
|---------------|-------------------------------------------------------------------------------------------------------|
| {$NFSVERSION} | the NFS version that should be returned by the server |
| {$NFSSHARES} | the list of NFS shares that should be available, to set multiple shares they must be separated by `,` |
Exemple:
![Zabbix NFS configuration sample](https://tool.frogg.fr/upload/github/zabbix-nfs/macros-1.0.4.png)
# Template items
![Zabbix NFS Template](https://tool.frogg.fr/upload/github/zabbix-nfs/items-1.0.4.png)
# Template triggers
![Zabbix NFS Template triggers](https://tool.frogg.fr/upload/github/zabbix-nfs/triggers-1.0.4.png)
# Debugging
Going further...This step is working with most of the externals scripts
If you got troubles getting an external script working, first :
1. Check the Zabbix tab **Monitoring > latest data**
If you select a host, you should see all items linked to it, check for your item, and you should see the lasted data linked to it.
If it appears in gray (disabled) that mean there is something wrong with the external script (rights, path, arguments ...)
To find more about it, you can check logs
2. By default, the logs are in `/var/log/zabbix/zabbix_server.log` or you can find the log path in Zabbix configuration file `zabbix_server.conf` (by default `/etc/zabbix/zabbix_server.conf`)
To get the last log lines you can use for example:
```bash
tail -f /var/log/zabbix/zabbix_server.log
```
Then look at the script trouble...
Example:
![Zabbix NFS error sample](https://tool.frogg.fr/upload/github/zabbix-nfs/error.png)
In this case Zabbix cannot find the path of the script as you can see *no such file or directory*
# Contributors
[![](https://avatars.githubusercontent.com/u/3765812?s=50&u=a377d0b319be56f5917f500be1ea24f2610324c7&v=4)](https://github.com/FroggDev)
[![](https://avatars.githubusercontent.com/u/48913164?s=50&u=a148e291f87278136cbbcd1a303911a2bd7777d2&v=4)](https://github.com/SiKreuz)

99
frogg_nfs_check.sh Normal file
View File

@ -0,0 +1,99 @@
#!/bin/bash
# _ __ _
# ((-)).--.((-))
# / '' \
# ( \______/ )
# \ ( ) /
# / /~~~~~~~~\ \
# /~~\/ / \ \/~~\
# ( ( ( ) ) )
# \ \ \ \ / / / /
# _\ \/ \.______./ \/ /_
# ___/ /\__________/\ \___
# *****************************
# Frogg - admin@frogg.fr
# http://github.com/FroggDev/zabbix-nfs
# *****************************
##########
# PARAMS #
##########
NFSACTION=$1
NFSSERVER=$2
NFSSHARES=$3
#############
# Functions #
#############
# ---
# Get the NFS version of a server
# @param serverIP
# @return NFS version
function getNfsVersion()
{
# Init NFS version to 0 = unavailable
VERSION=0
# Get NFS information using rpcinfo without error messages
TESTNFS=$(rpcinfo -t $1 nfs 2> /dev/null)
# Split all lines in the array TESTNFS
IFS=$'\n' read -rd '' -a TESTNFSLINES <<<"$TESTNFS"
# Loop over all lines of the array TESTNFSLINES
for TESTNFSLINE in "${TESTNFSLINES[@]}";
do
[[ $TESTNFSLINE =~ "version 2 ready and waiting" ]] && VERSION=2
[[ $TESTNFSLINE =~ "version 3 ready and waiting" ]] && VERSION=3
[[ $TESTNFSLINE =~ "version 4 ready and waiting" ]] && VERSION=4
done;
# Display the NFS version or 0 if not available
echo $VERSION
}
# ---
# Get the NFS version of a server
# @param serverIP
# @param nfs share list separated with :
# @return nfs share not found
function checkNfsShare()
{
# Init NFS share not available (epmty by default)
RESULT=""
# Get NFS information using showmount without error messages
NFSDATA=$(showmount -e $1 2> /dev/null)
# Store the result as array
IFS=$'\n' read -rd '' -a NFSDATAS <<< "$NFSDATA"
# Get NFS share set as params and store it as an array
SHARES=$(echo $2 | tr "," "\n")
#For each NFS share test if exist in server NFS share list
for SHARE in $SHARES
do
# Check if NFS share does not exist in NFS server shares
[[ ! " ${NFSDATAS[@]} " =~ " ${SHARE} " ]] && RESULT="${RESULT}[${SHARE}]"
done
echo $RESULT
}
########
# MAIN #
########
# Clean screen
#clear
case ${NFSACTION} in
# command check version
("version")echo $(getNfsVersion "$NFSSERVER");;
# command check nfs share
("share")echo $(checkNfsShare "$NFSSERVER" "$NFSSHARES");;
# command not set or invalid
(*)echo "Error : command [${NFSACTION}] not found"
esac

92
zabbix_template_v5.2.xml Normal file
View File

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>5.2</version>
<date>2021-03-14T13:31:06Z</date>
<groups>
<group>
<name>Templates</name>
</group>
<group>
<name>Templates/Modules</name>
</group>
</groups>
<templates>
<template>
<template>NFS Share</template>
<name>Template Module NFS Share</name>
<description>This template check NFS version and shares</description>
<groups>
<group>
<name>Templates</name>
</group>
<group>
<name>Templates/Modules</name>
</group>
</groups>
<applications>
<application>
<name>NFS</name>
</application>
</applications>
<items>
<item>
<name>NFS share</name>
<key>nfsshare.share[{HOST.CONN},{$NFSSHARES}]</key>
<delay>2m</delay>
<history>7d</history>
<trends>0</trends>
<value_type>TEXT</value_type>
<applications>
<application>
<name>NFS</name>
</application>
</applications>
<triggers>
<trigger>
<expression>{strlen()}&gt;0</expression>
<name>NFS share {ITEM.VALUE} unavailable on {HOST.NAME}</name>
<priority>AVERAGE</priority>
</trigger>
</triggers>
</item>
<item>
<name>Check NFS version</name>
<key>nfsshare.version[{HOST.CONN}]</key>
<delay>30m</delay>
<history>7d</history>
<trends>0</trends>
<value_type>FLOAT</value_type>
<applications>
<application>
<name>NFS</name>
</application>
</applications>
<triggers>
<trigger>
<expression>{last()}=0</expression>
<name>NFS service is down on {HOST.NAME}</name>
<priority>AVERAGE</priority>
</trigger>
<trigger>
<expression>{last()}&lt;&gt;{$NFSVERSION}</expression>
<name>NFS version is {ITEM.VALUE} instead of {$NFSVERSION} on {HOST.NAME}</name>
<priority>WARNING</priority>
</trigger>
</triggers>
</item>
</items>
<macros>
<macro>
<macro>{$NFSSHARES}</macro>
<value>/nfsshare1,/nfsshare2</value>
<description>List of shares separated by ,</description>
</macro>
<macro>
<macro>{$NFSVERSION}</macro>
<value>4</value>
<description>NFS version expected</description>
</macro>
</macros>
</template>
</templates>
</zabbix_export>

98
zabbix_template_v6.json Normal file
View File

@ -0,0 +1,98 @@
{
"zabbix_export": {
"version": "6.0",
"date": "2026-05-15T18:35:42Z",
"groups": [
{
"uuid": "7df96b18c230490a9a0a9e2307226338",
"name": "Templates"
},
{
"uuid": "57b7ae836ca64446ba2c296389c009b7",
"name": "Templates/Modules"
}
],
"templates": [
{
"uuid": "f06ff2609709457a8b293b20673a2a38",
"template": "NFS Share",
"name": "Template Module NFS Share",
"description": "This template check NFS version and shares",
"groups": [
{
"name": "Templates"
},
{
"name": "Templates/Modules"
}
],
"items": [
{
"uuid": "8d5b183b54ae4553b40e9ac5a97057bd",
"name": "NFS share",
"key": "nfsshare.share[{HOST.CONN},{$NFSSHARES}]",
"delay": "2m",
"history": "7d",
"trends": "0",
"value_type": "TEXT",
"tags": [
{
"tag": "Application",
"value": "NFS"
}
],
"triggers": [
{
"uuid": "ff189fd566634a8dba0c50629bc6b308",
"expression": "length(last(/NFS Share/nfsshare.share[{HOST.CONN},{$NFSSHARES}]))>0",
"name": "NFS share {ITEM.VALUE} unavailable on {HOST.NAME}",
"priority": "AVERAGE"
}
]
},
{
"uuid": "131cded651f94bbaabe6dbd674cd91ef",
"name": "Check NFS version",
"key": "nfsshare.version[{HOST.CONN}]",
"delay": "30m",
"history": "7d",
"trends": "0",
"value_type": "FLOAT",
"tags": [
{
"tag": "Application",
"value": "NFS"
}
],
"triggers": [
{
"uuid": "ee493a5919a041c5bc1d10fb7819ce8e",
"expression": "last(/NFS Share/nfsshare.version[{HOST.CONN}])=0",
"name": "NFS service is down on {HOST.NAME}",
"priority": "AVERAGE"
},
{
"uuid": "e883f03d35a54273a6513637f88bbf91",
"expression": "last(/NFS Share/nfsshare.version[{HOST.CONN}])<>{$NFSVERSION}",
"name": "NFS version is {ITEM.VALUE} instead of {$NFSVERSION} on {HOST.NAME}",
"priority": "WARNING"
}
]
}
],
"macros": [
{
"macro": "{$NFSSHARES}",
"value": "/nfsshare1,/nfsshare2",
"description": "List of shares separated by ,"
},
{
"macro": "{$NFSVERSION}",
"value": "4",
"description": "NFS version expected"
}
]
}
]
}
}

97
zabbix_template_v7.json Normal file
View File

@ -0,0 +1,97 @@
{
"zabbix_export": {
"version": "7.0",
"template_groups": [
{
"uuid": "7df96b18c230490a9a0a9e2307226338",
"name": "Templates"
},
{
"uuid": "57b7ae836ca64446ba2c296389c009b7",
"name": "Templates/Modules"
}
],
"templates": [
{
"uuid": "f06ff2609709457a8b293b20673a2a38",
"template": "NFS Share",
"name": "Template Module NFS Share",
"description": "This template check NFS version and shares",
"groups": [
{
"name": "Templates"
},
{
"name": "Templates/Modules"
}
],
"items": [
{
"uuid": "8d5b183b54ae4553b40e9ac5a97057bd",
"name": "NFS share",
"key": "nfsshare.share[{HOST.CONN},{$NFSSHARES}]",
"delay": "2m",
"history": "7d",
"trends": "0",
"value_type": "TEXT",
"tags": [
{
"tag": "Application",
"value": "NFS"
}
],
"triggers": [
{
"uuid": "ff189fd566634a8dba0c50629bc6b308",
"expression": "length(last(/NFS Share/nfsshare.share[{HOST.CONN},{$NFSSHARES}]))>0",
"name": "NFS share {ITEM.VALUE} unavailable on {HOST.NAME}",
"priority": "AVERAGE"
}
]
},
{
"uuid": "131cded651f94bbaabe6dbd674cd91ef",
"name": "Check NFS version",
"key": "nfsshare.version[{HOST.CONN}]",
"delay": "30m",
"history": "7d",
"trends": "0",
"value_type": "FLOAT",
"tags": [
{
"tag": "Application",
"value": "NFS"
}
],
"triggers": [
{
"uuid": "ee493a5919a041c5bc1d10fb7819ce8e",
"expression": "last(/NFS Share/nfsshare.version[{HOST.CONN}])=0",
"name": "NFS service is down on {HOST.NAME}",
"priority": "AVERAGE"
},
{
"uuid": "e883f03d35a54273a6513637f88bbf91",
"expression": "last(/NFS Share/nfsshare.version[{HOST.CONN}])<>{$NFSVERSION}",
"name": "NFS version is {ITEM.VALUE} instead of {$NFSVERSION} on {HOST.NAME}",
"priority": "WARNING"
}
]
}
],
"macros": [
{
"macro": "{$NFSSHARES}",
"value": "/nfsshare1,/nfsshare2",
"description": "List of shares separated by ,"
},
{
"macro": "{$NFSVERSION}",
"value": "4",
"description": "NFS version expected"
}
]
}
]
}
}