NagiosXI Web Console Login Alert Shell Script
Get Alert when user logged into NagiosXI Web Console Login Alert by scheduling below script to crontab. Which i have written for internal requirement maybe useful for you. Here i am using the logic to convert actual time into epoc time and comparing the same based on time period alert will be generated.
NagiosXI Web Console Login Alert
#!/bin/bash
# Purpose: To get alerts when user is logged in to Nagiosxi console
# Author: Ankam Ravi Kumar
# Date: 25-May-2017
# NagiosXI Server
DT=`date +%Y-%m-%d`
psql -U USERNAME -d PASSWORD -t -A -F"," -c "select * from xi_auditlog;" > /tmp/auditlog.txt
cat /tmp/auditlog.txt |grep $DT > /tmp/today.txt
EPOCTIME=`cat /tmp/today.txt |awk -F, '{print $2}' |tail -1`
ENDTIME=$(date +%s)
STARTIME=$(date +%s -d"$EPOCTIME")
echo $((ENDTIME-STARTIME)) | awk '{print int($1/60)}' > /tmp/value1
count=`cat /tmp/value1`
if [ $count -lt 8 ]
then
cat /tmp/auditlog.txt |grep $DT |tail -1 > /tmp/mail
mail -s "NagiosXI Login ALERT: `cat /tmp/mail | awk -F, '{print $4}'` `cat /tmp/mail | awk -F, '{print $6}'` to `hostname` `date`" EMAILID@DOMAIN.COM < /tmp/mail
fi
rm -rf /tmp/auditlog.txt /tmp/today.txt /tmp/value1 /tmp/mail
Create file in your Linux machine example ngxlogin.sh
vi ngxlogin.sh
Copy above script to and paste into ngxlogin.sh file and replace required details
chmod u+x ngxlogin.sh
Edit crontab and add below entry
crontab -e */5 * * * * sh ngxlogin.sh
That’s it when user is logged into Nagiosxi web console Login alert will sent to your email id.
Related Articles
Linux Server Monitoring using SNMP
Thanks for Your Wonderful Support and Encouragement
More than 40,000 techies are part of our ARKIT community. Join us today and keep learning Linux, Cloud, Storage, DevOps, and IT technologies.