From 2dc144d356f6299fc82405181b01a7c2b84552d5 Mon Sep 17 00:00:00 2001 From: Frogg Date: Fri, 15 May 2026 20:40:46 +0200 Subject: [PATCH] Ajout des fichiers du projet --- CHANGELOG.md | 8 +++ README.md | 137 +++++++++++++++++++++++++++++++++++++++ frogg_nfs_check.sh | 99 ++++++++++++++++++++++++++++ zabbix_template_v5.2.xml | 92 ++++++++++++++++++++++++++ zabbix_template_v6.json | 98 ++++++++++++++++++++++++++++ zabbix_template_v7.json | 97 +++++++++++++++++++++++++++ 6 files changed, 531 insertions(+) create mode 100644 frogg_nfs_check.sh create mode 100644 zabbix_template_v5.2.xml create mode 100644 zabbix_template_v6.json create mode 100644 zabbix_template_v7.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b13789..f59c5f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 8b13789..39ea568 100644 --- a/README.md +++ b/README.md @@ -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 +``` +- To Test NFS share +``` +./frogg_nfs_check.sh share "/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) \ No newline at end of file diff --git a/frogg_nfs_check.sh b/frogg_nfs_check.sh new file mode 100644 index 0000000..745d5be --- /dev/null +++ b/frogg_nfs_check.sh @@ -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 diff --git a/zabbix_template_v5.2.xml b/zabbix_template_v5.2.xml new file mode 100644 index 0000000..83ecf7f --- /dev/null +++ b/zabbix_template_v5.2.xml @@ -0,0 +1,92 @@ + + + 5.2 + 2021-03-14T13:31:06Z + + + Templates + + + Templates/Modules + + + + + + \ No newline at end of file diff --git a/zabbix_template_v6.json b/zabbix_template_v6.json new file mode 100644 index 0000000..3514c62 --- /dev/null +++ b/zabbix_template_v6.json @@ -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" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/zabbix_template_v7.json b/zabbix_template_v7.json new file mode 100644 index 0000000..7e6406d --- /dev/null +++ b/zabbix_template_v7.json @@ -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" + } + ] + } + ] + } +} \ No newline at end of file