<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export><version>5.0</version><date>2021-11-21T21:31:51Z</date><groups><group><name>Templates</name></group></groups><templates><template><template>Linux_Services</template><name>Linux Services</name><description>## Overview

This script detects processes that are running for a while and presumes that these are services that should be running always. The magic is in the regular expression.  
The LLD-template will use the JSON-output to create the item proc.num[{#SERVICE}] for each of these processes and a trigger that will check if it is running or not.


This takes away the need to specify in your template which service is supposed to be running.


If it detects a service that does not need monitoring you can always disable it. If the service should never be monitored it is better to add these to the &quot;Global regular expressions&quot; of Zabbix (or in the script).


 */etc/zabbix/scripts/service\_discovery*


**#!/bin/bash**


**TMPDIR=`mktemp -t -d ${0//*\/}.XXXXXXXXXX`**


**echo '^-**


**^\_****^sleep$****^qmgr$****^showq$****^pickup$****^pigz$****^tar$****^pmm-ras$****^backupmng$****^proxymap$****^cleanup$****^tlsmgr$****^anvil$****^trivial-rewrite$****^dd$****^init$****^php****^perl$****^python$****^lua$****^sh$****^bash$****^auth$****^login$****^imap****^accounts-daemon$****^config$****^ssl-params$****^vlogger$****^ssh$****^zabbix\_agent****^systemd****^proxymap$****zip$****^awk$****^log$****^run-parts$****getty$****^smtp$****^smtpd$****^amavisd****^postgrey****^pure-ftpd****^proftpd****^Passenger****^qsync****^qWatchdogd****^spamd$' &gt;${TMPDIR}/filter**


**ps aux | egrep -io '([a-z]+[0-9]+| 20[0-9][0-9]) +[0-9]+:[0-9]+ [A-Za-z0-9/\_-]*( |:|$)' | \** **sed 's/.*\///g;s/[ :]$//g;s/.* //g' | grep '[a-z]' | \** **grep -vf ${TMPDIR}/filter | sort | uniq &gt;${TMPDIR}/progs**


**if [ -s ${TMPDIR}/progs ] ; then** **echo -e &quot;{\n\t\&quot;data\&quot;:[&quot;** **while read SERVICE ; do** **[ ${PRINTED} ] &amp;&amp; echo &quot;,&quot;** **PRINTED=true** **echo -en &quot;\t\t{ \&quot;{#SERVICE}\&quot;:\&quot;${SERVICE}\&quot; }&quot;** **done &lt;${TMPDIR}/progs** **echo -e &quot;\n\t]\n}&quot;****fi**  
**rm -r ${TMPDIR}**


 



## Author

Frater

</description><groups><group><name>Templates</name></group></groups><discovery_rules><discovery_rule><name>Linux service discovery</name><key>service.discovery</key><delay>1h</delay><filter><conditions><condition><macro>{#SERVICE}</macro><value>@Linux service name for discovery</value><formulaid>A</formulaid></condition></conditions></filter><item_prototypes><item_prototype><name>Number of processes $1</name><key>proc.num[{#SERVICE}]</key><delay>2m</delay><trigger_prototypes><trigger_prototype><expression>{last()}=0</expression><name>Service {#SERVICE} is not running</name><priority>HIGH</priority></trigger_prototype></trigger_prototypes></item_prototype></item_prototypes></discovery_rule></discovery_rules></template></templates></zabbix_export>
