monitnotifyer: init (multy and notsentmessages missing) ; monitnotify.service_sample: init ; pretigger_notification.sh_sample: init
This commit is contained in:
		
							parent
							
								
									0181978500
								
							
						
					
					
						commit
						6fb45ddc0f
					
				| 
						 | 
					@ -0,0 +1,18 @@
 | 
				
			||||||
 | 
					[Unit]
 | 
				
			||||||
 | 
					Description=Monit mail notify wrapper
 | 
				
			||||||
 | 
					Documentation=https://gitea.sons-of-sparda.at/oliver.schraml/monitnotifyer
 | 
				
			||||||
 | 
					Before=monit.service
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[Service]
 | 
				
			||||||
 | 
					User=yourmonitoringmailuser
 | 
				
			||||||
 | 
					Group=yourmonitoringmailuser
 | 
				
			||||||
 | 
					Type=simple
 | 
				
			||||||
 | 
					ExecStart=/home/yourmonitoringmailuser/monitnotifyer/monitnotifyer.sh
 | 
				
			||||||
 | 
					ExecReload=/bin/kill -HUP $MAINPID
 | 
				
			||||||
 | 
					ExecStop=/bin/kill -HUP $MAINPID
 | 
				
			||||||
 | 
					KillMode=process
 | 
				
			||||||
 | 
					StandardOutput=null
 | 
				
			||||||
 | 
					Restart=on-failure
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[Install]
 | 
				
			||||||
 | 
					WantedBy=multi-user.target
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,35 @@
 | 
				
			||||||
 | 
					#!/bin/bash
 | 
				
			||||||
 | 
					scrpa="$(/usr/bin/dirname ${0})"
 | 
				
			||||||
 | 
					monitnotifymbox="/var/mail/monitnotify"
 | 
				
			||||||
 | 
					monitgrep='^Subject..Monit-Message|^Monit-(Date|Action|Host|Description)'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					trignotification() {
 | 
				
			||||||
 | 
					    mailmsg="$(cat ${monitnotifymbox} | grep -E "${monitgrep}")"
 | 
				
			||||||
 | 
					    if [ -n "${mailmsg}" ]
 | 
				
			||||||
 | 
					    then
 | 
				
			||||||
 | 
					        echo "Monitmail detected"
 | 
				
			||||||
 | 
					        if [ $(/bin/echo ${mailmsg} | /usr/bin/wc -l) -gt 5 ]; then
 | 
				
			||||||
 | 
					            multymsg=true
 | 
				
			||||||
 | 
					            echo "Detected multy mail"
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					            echo "Detected single mail"
 | 
				
			||||||
 | 
					            /bin/echo "d*" | /usr/bin/mail
 | 
				
			||||||
 | 
					            mservicename="$(/bin/echo "${mailmsg}" | /bin/grep -E '^Subject. Monit-Message' | /usr/bin/cut -f4 -d\:)"
 | 
				
			||||||
 | 
					            mservicestatus="$(/bin/echo "${mailmsg}" | /bin/grep -E '^Subject. Monit-Message' | /usr/bin/cut -f3 -d\:)"
 | 
				
			||||||
 | 
					            mserviceaction="$(/bin/echo "${mailmsg}" | /bin/grep -E '^Monit-Action' | /usr/bin/cut -f2 -d\:)"
 | 
				
			||||||
 | 
					            mservicehost="$(/bin/echo "${mailmsg}"  | /bin/grep -E '^Monit-Host.' | /usr/bin/cut -f2 -d\:)"
 | 
				
			||||||
 | 
					            mservicedesc="$(/bin/echo "${mailmsg}" | /bin/grep -E '^Monit-Description.' | /bin/sed -e 's/^Monit-Description.//g')"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            ${scrpa}/pretrigger_notification.sh "${mservicename}" "${mserviceaction}" "${mservicestatus}" "${mservicedesc}" "${mservicehost}" &
 | 
				
			||||||
 | 
					        fi
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        /bin/echo "Not a monit message, ignore it"
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/usr/bin/inotifywait -q -m -e close_write ${monitnotifymbox} |
 | 
				
			||||||
 | 
					while read -r filename events
 | 
				
			||||||
 | 
					do
 | 
				
			||||||
 | 
					    if [ "${filename}" == "${monitnotifymbox}" ] ; then trignotification ; fi
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,9 @@
 | 
				
			||||||
 | 
					#!/bin/bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					mservicename="${1}"
 | 
				
			||||||
 | 
					mserviceaction="${2}"
 | 
				
			||||||
 | 
					mservicestatus="${3}"
 | 
				
			||||||
 | 
					mservicedesc="${4}"
 | 
				
			||||||
 | 
					mservicehost="${5}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/home/myuser/mynotiicationscript.sh -d mydevice -t "[${mserviceaction}] ${mservicestatus} on ${mservicename}" "${mservicedesc}" &
 | 
				
			||||||
		Loading…
	
		Reference in New Issue