1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/zabbix_ynh.git synced 2024-09-03 20:36:14 +02:00
zabbix_ynh/conf/Template_Yunohost.xml
2022-07-12 00:36:01 +02:00

576 lines
No EOL
30 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>5.0</version>
<date>2020-11-26T12:48:35Z</date>
<groups>
<group>
<name>Templates/Applications</name>
</group>
</groups>
<templates>
<template>
<template>Template Yunohost</template>
<name>Template Yunohost</name>
<description>Please check default value template macro.&#13;
&#13;
cat /etc/sudoers.d/zabbix &#13;
zabbix ALL=(ALL) NOPASSWD: /etc/zabbix/zabbix_agentd.d/yunohost.sh&#13;
&#13;
cat /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf &#13;
UserParameter=yunohost.users.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.users.discover&#13;
UserParameter=yunohost.user.quota[*],sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.user.quota &quot;$1&quot;&#13;
UserParameter=yunohost.domains.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.domains.discover&#13;
UserParameter=yunohost.domain.cert[*],sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.domain.cert &quot;$1&quot;&#13;
UserParameter=yunohost.services.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.services.discover&#13;
UserParameter=yunohost.service.status[*],sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.service.status &quot;$1&quot;&#13;
UserParameter=yunohost.backups.number,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.backups.number&#13;
UserParameter=yunohost.backups.ageoflastbackup,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.backups.ageoflastbackup&#13;
UserParameter=yunohost.ports.tcp.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.ports.tcp.discovery&#13;
UserParameter=yunohost.ports.udp.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.ports.udp.discovery&#13;
UserParameter=yunohost.migrations.lastinstalled,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.migrations.lastinstalled&#13;
UserParameter=yunohost.migrations.lastavailable,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.migrations.lastavailable&#13;
&#13;
cat /etc/zabbix/zabbix_agentd.d/yunohost.sh &#13;
#!/bin/bash&#13;
yunobin=$(which yunohost)&#13;
&#13;
if [ &quot;$1&quot; == &quot;yunohost.users.discover&quot; ];then&#13;
users=$($yunobin user list --fields 'uid' | awk -F ': ' '/username: / {print $2}');echo -n &quot;{\&quot;data\&quot;:[&quot;;for user in $users;do echo -n &quot;{\&quot;{#USERNAME}\&quot;:\&quot;$user\&quot;},&quot;;done | sed 's/,$//' ;echo &quot;]}&quot;&#13;
fi&#13;
&#13;
if [ &quot;$1&quot; == &quot;yunohost.user.quota&quot; ] ;then&#13;
quota=$($yunobin user info &quot;$2&quot; | grep -Po &quot;use:.*\(\K([0-9]{1,3})&quot;);if [ -z &quot;$quota&quot; ];then echo 0 ; else echo &quot;$quota&quot; ;fi&#13;
fi&#13;
&#13;
if [ &quot;$1&quot; == &quot;yunohost.domains.discover&quot; ] ;then&#13;
domains=$($yunobin domain list --output-as plain);echo -n &quot;{\&quot;data\&quot;:[&quot;;for domain in $domains;do echo -n &quot;{\&quot;{#DOMAIN}\&quot;:\&quot;$domain\&quot;},&quot;;done | sed 's/,$//' ;echo &quot;]}&quot;&#13;
fi&#13;
&#13;
if [ &quot;$1&quot; == &quot;yunohost.domain.cert&quot; ] ;then&#13;
$yunobin domain cert-status &quot;$2&quot; --output-as plain --full| awk '/#/{ next;} {printf &quot;%s;&quot;,$0} END {print &quot;&quot;}'&#13;
fi&#13;
&#13;
if [ &quot;$1&quot; == &quot;yunohost.services.discover&quot; ] ;then&#13;
services=$($yunobin service status 2&gt;/dev/null| grep -Po '^([A-Za-z]+)(?=(:))');echo -n &quot;{\&quot;data\&quot;:[&quot;;for service in $services;do echo -n &quot;{\&quot;{#SERVICE}\&quot;:\&quot;$service\&quot;},&quot;;done | sed 's/,$//' ;echo &quot;]}&quot;&#13;
fi&#13;
&#13;
if [ &quot;$1&quot; == &quot;yunohost.service.status&quot; ] ;then&#13;
service=$($yunobin service status &quot;$2&quot; --output-as json 2&gt;/dev/null)&#13;
if [[ &quot;$(echo $service | jq -r '.description')&quot; == *&quot;doesn't exists for systemd&quot;* ]] ;then&#13;
echo &quot;$service&quot; | jq -c '.active = &quot;disabled&quot;' &#13;
else&#13;
echo &quot;$service&quot;&#13;
fi&#13;
fi&#13;
&#13;
if [ &quot;$1&quot; == &quot;yunohost.backups.number&quot; ] ;then&#13;
$yunobin backup list --output-as plain | wc -l&#13;
fi&#13;
&#13;
if [ &quot;$1&quot; == &quot;yunohost.backups.ageoflastbackup&quot; ] ;then&#13;
if [ $($yunobin backup list --output-as plain | wc -l) -ne 0 ] ;then&#13;
timestamp=$(date +&quot;%d/%m/%Y %H:%M&quot; -d&quot;$($yunobin backup list -i | tail -n 4 | head -n 1 | grep -Po 'created_at: \K(.*)')&quot;)&#13;
echo $(( ($(date +%s) - $(date -d&quot;$timestamp&quot; +%s))/(60*60*24) ))&#13;
else&#13;
echo &quot;No backup detected&quot;&#13;
fi&#13;
fi&#13;
&#13;
if [ &quot;$1&quot; == &quot;yunohost.ports.tcp.discovery&quot; ] ;then&#13;
ports=$($yunobin firewall list -r --output-as plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##TCP/{flag=1;next}/##TCP/{flag=0}flag');echo -n &quot;{\&quot;data\&quot;:[&quot;;for port in $ports;do echo -n &quot;{\&quot;{#PORT}\&quot;:\&quot;$port\&quot;},&quot;;done | sed 's/,$//' ;echo &quot;]}&quot;&#13;
fi&#13;
&#13;
if [ &quot;$1&quot; == &quot;yunohost.ports.udp.discovery&quot; ] ;then&#13;
ports=$($yunobin firewall list -r --output-as plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##UDP/{flag=1;next}/##TCP/{flag=0}flag');echo -n &quot;{\&quot;data\&quot;:[&quot;;for port in $ports;do echo -n &quot;{\&quot;{#PORT}\&quot;:\&quot;$port\&quot;},&quot;;done | sed 's/,$//' ;echo &quot;]}&quot;&#13;
fi&#13;
&#13;
if [ &quot;$1&quot; == &quot;yunohost.migrations.lastinstalled&quot; ] ;then&#13;
$yunobin tools migrations state | grep -Po &quot; number: \K(.*)&quot;&#13;
fi&#13;
&#13;
if [ &quot;$1&quot; == &quot;yunohost.migrations.lastavailable&quot; ] ;then&#13;
$yunobin tools migrations list | tail -n 1 | grep -Po &quot; number: \K(.*)&quot;&#13;
fi</description>
<groups>
<group>
<name>Templates/Applications</name>
</group>
</groups>
<applications>
<application>
<name>Yunohost : Backups</name>
</application>
<application>
<name>Yunohost : Certificates</name>
</application>
<application>
<name>Yunohost : Certificates : Expiration</name>
</application>
<application>
<name>Yunohost : Certificates : State</name>
</application>
<application>
<name>Yunohost : Migrations</name>
</application>
<application>
<name>Yunohost : Ports</name>
</application>
<application>
<name>Yunohost : Services</name>
</application>
<application>
<name>Yunohost : Services : Status</name>
</application>
<application>
<name>Yunohost : Users</name>
</application>
</applications>
<items>
<item>
<name>Age of the last backup</name>
<key>yunohost.backups.ageoflastbackup</key>
<delay>1d;h10m45</delay>
<units>days</units>
<applications>
<application>
<name>Yunohost : Backups</name>
</application>
</applications>
<triggers>
<trigger>
<expression>{last()}&gt;={$YUNOHOST.BACKUP.MAXDAYS}</expression>
<name>YunoHost hasn't backup since more than {$YUNOHOST.BACKUP.MAXDAYS} days</name>
<opdata>{ITEM.LASTVALUE}</opdata>
<priority>HIGH</priority>
<description>Please check https://yunohost.org/en/backup</description>
<manual_close>YES</manual_close>
</trigger>
</triggers>
</item>
<item>
<name>Number of Yunohost backups</name>
<key>yunohost.backups.number</key>
<delay>1d;h11</delay>
<applications>
<application>
<name>Yunohost : Backups</name>
</application>
</applications>
<triggers>
<trigger>
<expression>{last()}=0</expression>
<name>YunoHost hasn't backup yet</name>
<priority>HIGH</priority>
<description>Please check https://yunohost.org/en/backup</description>
<manual_close>YES</manual_close>
</trigger>
</triggers>
</item>
<item>
<name>Id of the last migration available</name>
<key>yunohost.migrations.lastavailable</key>
<delay>1d;h10m50</delay>
<applications>
<application>
<name>Yunohost : Migrations</name>
</application>
</applications>
</item>
<item>
<name>Id of the last migration installed</name>
<key>yunohost.migrations.lastinstalled</key>
<delay>1d;h10m55</delay>
<applications>
<application>
<name>Yunohost : Migrations</name>
</application>
</applications>
</item>
</items>
<discovery_rules>
<discovery_rule>
<name>Yunohost domains</name>
<key>yunohost.domains.discover</key>
<delay>1d;h10</delay>
<item_prototypes>
<item_prototype>
<name>Certificate {#DOMAIN} expiration</name>
<type>DEPENDENT</type>
<key>yunohost.domain.cert.expiration[{#DOMAIN}]</key>
<delay>0</delay>
<history>180d</history>
<units>d</units>
<applications>
<application>
<name>Yunohost : Certificates</name>
</application>
<application>
<name>Yunohost : Certificates : Expiration</name>
</application>
</applications>
<preprocessing>
<step>
<type>REGEX</type>
<params>(.*);(.*);(.*);(.*);(.*);(.*);(.*);(.*);
\2</params>
</step>
</preprocessing>
<master_item>
<key>yunohost.domain.cert[{#DOMAIN}]</key>
</master_item>
<trigger_prototypes>
<trigger_prototype>
<expression>{last()}&lt;{$YUNOHOST.CERTIFICATE.REMAININGDAYS_AVG}</expression>
<name>Remaining days for certificate {#DOMAIN} &lt; {$YUNOHOST.CERTIFICATE.REMAININGDAYS_AVG}</name>
<opdata>{ITEM.LASTVALUE}</opdata>
<priority>AVERAGE</priority>
<dependencies>
<dependency>
<name>Remaining days for certificate {#DOMAIN} &lt; {$YUNOHOST.CERTIFICATE.REMAININGDAYS_DISASTER}</name>
<expression>{Template Yunohost:yunohost.domain.cert.expiration[{#DOMAIN}].last()}&lt; {$YUNOHOST.CERTIFICATE.REMAININGDAYS_DISASTER}</expression>
</dependency>
<dependency>
<name>Remaining days for certificate {#DOMAIN} &lt; {$YUNOHOST.CERTIFICATE.REMAININGDAYS_HIGH}</name>
<expression>{Template Yunohost:yunohost.domain.cert.expiration[{#DOMAIN}].last()}&lt;{$YUNOHOST.CERTIFICATE.REMAININGDAYS_HIGH}</expression>
</dependency>
</dependencies>
</trigger_prototype>
<trigger_prototype>
<expression>{last()}&lt; {$YUNOHOST.CERTIFICATE.REMAININGDAYS_DISASTER}</expression>
<name>Remaining days for certificate {#DOMAIN} &lt; {$YUNOHOST.CERTIFICATE.REMAININGDAYS_DISASTER}</name>
<opdata>{ITEM.LASTVALUE}</opdata>
<priority>DISASTER</priority>
</trigger_prototype>
<trigger_prototype>
<expression>{last()}&lt;{$YUNOHOST.CERTIFICATE.REMAININGDAYS_HIGH}</expression>
<name>Remaining days for certificate {#DOMAIN} &lt; {$YUNOHOST.CERTIFICATE.REMAININGDAYS_HIGH}</name>
<opdata>{ITEM.LASTVALUE}</opdata>
<priority>HIGH</priority>
<dependencies>
<dependency>
<name>Remaining days for certificate {#DOMAIN} &lt; {$YUNOHOST.CERTIFICATE.REMAININGDAYS_DISASTER}</name>
<expression>{Template Yunohost:yunohost.domain.cert.expiration[{#DOMAIN}].last()}&lt; {$YUNOHOST.CERTIFICATE.REMAININGDAYS_DISASTER}</expression>
</dependency>
</dependencies>
</trigger_prototype>
</trigger_prototypes>
</item_prototype>
<item_prototype>
<name>Certificate {#DOMAIN} state</name>
<type>DEPENDENT</type>
<key>yunohost.domain.cert.state[{#DOMAIN}]</key>
<delay>0</delay>
<history>180d</history>
<trends>0</trends>
<value_type>CHAR</value_type>
<applications>
<application>
<name>Yunohost : Certificates</name>
</application>
<application>
<name>Yunohost : Certificates : State</name>
</application>
</applications>
<valuemap>
<name>Yunohost : certificates</name>
</valuemap>
<preprocessing>
<step>
<type>REGEX</type>
<params>(.*);(.*);(.*);(.*);(.*);(.*);(.*);(.*);
\3:unknown=0:critical=1:warning=2:attention=3:good=4;great=5</params>
</step>
<step>
<type>REGEX</type>
<params>^(unknown|critical|warning|attention|good|great):(?=.*\1=(\d))
\2</params>
</step>
</preprocessing>
<master_item>
<key>yunohost.domain.cert[{#DOMAIN}]</key>
</master_item>
</item_prototype>
<item_prototype>
<name>Informations {#DOMAIN} full</name>
<key>yunohost.domain.cert[{#DOMAIN}]</key>
<delay>1d</delay>
<history>180d</history>
<trends>0</trends>
<value_type>CHAR</value_type>
<applications>
<application>
<name>Yunohost : Certificates</name>
</application>
</applications>
</item_prototype>
</item_prototypes>
</discovery_rule>
<discovery_rule>
<name>TCP Ports opened</name>
<key>yunohost.ports.tcp.discover</key>
<delay>1d;h9m30</delay>
<lifetime>7d</lifetime>
<item_prototypes>
<item_prototype>
<name>Check TCP port {#PORT} responding</name>
<key>net.tcp.service[tcp,127.0.0.1,{#PORT}]</key>
<delay>900s</delay>
<applications>
<application>
<name>Yunohost : Ports</name>
</application>
</applications>
<valuemap>
<name>Yunohost : Service state</name>
</valuemap>
<trigger_prototypes>
<trigger_prototype>
<expression>{last()}=0</expression>
<name>TCP port {#PORT} not responding</name>
<priority>HIGH</priority>
<manual_close>YES</manual_close>
</trigger_prototype>
</trigger_prototypes>
</item_prototype>
</item_prototypes>
</discovery_rule>
<discovery_rule>
<name>UDP Ports opened</name>
<key>yunohost.ports.udp.discover</key>
<delay>1d;h9m45</delay>
<lifetime>0d</lifetime>
<item_prototypes>
<item_prototype>
<name>Check UDP port {#PORT} listening</name>
<key>net.udp.listen[{#PORT}]</key>
<delay>900s</delay>
<applications>
<application>
<name>Yunohost : Ports</name>
</application>
</applications>
<valuemap>
<name>Yunohost : Service state</name>
</valuemap>
<trigger_prototypes>
<trigger_prototype>
<expression>{last()}=0</expression>
<name>UDP port {#PORT} not listening</name>
<priority>HIGH</priority>
<manual_close>YES</manual_close>
</trigger_prototype>
</trigger_prototypes>
</item_prototype>
</item_prototypes>
</discovery_rule>
<discovery_rule>
<name>Yunohost services</name>
<key>yunohost.services.discover</key>
<delay>1d;h10m15</delay>
<lifetime>7d</lifetime>
<item_prototypes>
<item_prototype>
<name>Yunohost service {#SERVICE} status</name>
<type>DEPENDENT</type>
<key>yunohost.service.statusrunp[{#SERVICE}]</key>
<delay>0</delay>
<history>7d</history>
<applications>
<application>
<name>Yunohost : Services</name>
</application>
<application>
<name>Yunohost : Services : Status</name>
</application>
</applications>
<valuemap>
<name>Yunohost : services</name>
</valuemap>
<preprocessing>
<step>
<type>JSONPATH</type>
<params>$.active</params>
</step>
<step>
<type>REGEX</type>
<params>(.*)
\1:inactive=0:active=1:unknown=2;disabled=3</params>
</step>
<step>
<type>REGEX</type>
<params>^(inactive|active|unknown|disabled):(?=.*\1=(\d))
\2</params>
</step>
</preprocessing>
<master_item>
<key>yunohost.service.status[{#SERVICE}]</key>
</master_item>
<trigger_prototypes>
<trigger_prototype>
<expression>{last()}=3</expression>
<name>Service {#SERVICE} disabled</name>
<priority>HIGH</priority>
<manual_close>YES</manual_close>
</trigger_prototype>
<trigger_prototype>
<expression>{last()}=0</expression>
<name>Service {#SERVICE} state is inactive</name>
<priority>HIGH</priority>
<manual_close>YES</manual_close>
</trigger_prototype>
<trigger_prototype>
<expression>{last()}=2</expression>
<name>Service {#SERVICE} state is unknown</name>
<priority>HIGH</priority>
<manual_close>YES</manual_close>
</trigger_prototype>
</trigger_prototypes>
</item_prototype>
<item_prototype>
<name>Yunohost service {#SERVICE} status (full)</name>
<key>yunohost.service.status[{#SERVICE}]</key>
<delay>15m</delay>
<history>7d</history>
<trends>0</trends>
<value_type>CHAR</value_type>
<applications>
<application>
<name>Yunohost : Services</name>
</application>
</applications>
</item_prototype>
</item_prototypes>
</discovery_rule>
<discovery_rule>
<name>Yunohost users</name>
<key>yunohost.users.discover</key>
<delay>1d;h10m30</delay>
<item_prototypes>
<item_prototype>
<name>Quota percent for user {#USERNAME}</name>
<key>yunohost.user.quota[{#USERNAME}]</key>
<delay>1h</delay>
<history>30d</history>
<units>%</units>
<applications>
<application>
<name>Yunohost : Users</name>
</application>
</applications>
<trigger_prototypes>
<trigger_prototype>
<expression>{last()}&gt;=80</expression>
<name>User {#USERNAME} quota exceed 80%</name>
<priority>AVERAGE</priority>
<manual_close>YES</manual_close>
</trigger_prototype>
<trigger_prototype>
<expression>{last()}&gt;=90</expression>
<name>User {#USERNAME} quota exceed 90%</name>
<priority>HIGH</priority>
<manual_close>YES</manual_close>
</trigger_prototype>
</trigger_prototypes>
</item_prototype>
</item_prototypes>
</discovery_rule>
</discovery_rules>
<macros>
<macro>
<macro>{$YUNOHOST.BACKUP.MAXDAYS}</macro>
<value>7</value>
<description>The oldest backup age in day before trigger</description>
</macro>
<macro>
<macro>{$YUNOHOST.CERTIFICATE.REMAININGDAYS_AVG}</macro>
<value>14</value>
<description>Expiration date in X days AVG trigger</description>
</macro>
<macro>
<macro>{$YUNOHOST.CERTIFICATE.REMAININGDAYS_DISASTER}</macro>
<value>1</value>
<description>Expiration date in X days DISASTER trigger</description>
</macro>
<macro>
<macro>{$YUNOHOST.CERTIFICATE.REMAININGDAYS_HIGH}</macro>
<value>7</value>
<description>Expiration date in X days HIGH trigger</description>
</macro>
</macros>
</template>
</templates>
<triggers>
<trigger>
<expression>{Template Yunohost:yunohost.migrations.lastavailable.last()}&lt;&gt;{Template Yunohost:yunohost.migrations.lastinstalled.last()}</expression>
<name>YunoHost has migration in pending state</name>
<priority>INFO</priority>
<description>Check Yunohost documentation and &quot;yunohost/admin/#/tools/migrations/ &quot; url or &quot;sudo yunohost tools migrations migrate&quot; command</description>
<manual_close>YES</manual_close>
</trigger>
</triggers>
<value_maps>
<value_map>
<name>Yunohost : Service state</name>
<mappings>
<mapping>
<value>0</value>
<newvalue>Down</newvalue>
</mapping>
<mapping>
<value>1</value>
<newvalue>Up</newvalue>
</mapping>
</mappings>
</value_map>
<value_map>
<name>Yunohost : certificates</name>
<mappings>
<mapping>
<value>0</value>
<newvalue>unknown</newvalue>
</mapping>
<mapping>
<value>1</value>
<newvalue>critical</newvalue>
</mapping>
<mapping>
<value>2</value>
<newvalue>warning</newvalue>
</mapping>
<mapping>
<value>3</value>
<newvalue>attention</newvalue>
</mapping>
<mapping>
<value>4</value>
<newvalue>good</newvalue>
</mapping>
<mapping>
<value>5</value>
<newvalue>great</newvalue>
</mapping>
</mappings>
</value_map>
<value_map>
<name>Yunohost : services</name>
<mappings>
<mapping>
<value>0</value>
<newvalue>inactive</newvalue>
</mapping>
<mapping>
<value>1</value>
<newvalue>active</newvalue>
</mapping>
<mapping>
<value>2</value>
<newvalue>unknow</newvalue>
</mapping>
<mapping>
<value>3</value>
<newvalue>disabled</newvalue>
</mapping>
</mappings>
</value_map>
</value_maps>
</zabbix_export>