Skip to content

ARKIT

  • Home
  • About Us
  • Free Books
  • Netapp
  • Subscribe
  • Interview
  • MSSQL
  • Contribute
  • Videos
  • Linux Training
  • Home
  • About Us
  • Free Books
  • Netapp
  • Subscribe
  • Interview
  • MSSQL
  • Contribute
  • Videos
  • Linux Training

ARKIT

- Learners Guide.

  • Home
  • About Us
  • Linux
  • Hardware
  • Monitoring Tools
  • Scripting
  • VMWare
  • Interview
  • Automation
  • Ask Support
  • Netapp Training
  • AIX
  • Networking
  • Nagios / shell scripting

NagiosXI Web Console Login Alert Shell Script

by Ravi Kumar Ankam · Published May 25, 2017 · Updated August 19, 2017

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

NAgiosr

NSP Sorry Dave Error

Linux Server Monitoring using SNMP

Thanks for your wonderful Support and Encouragement

  • Get Email | Download E-Books
  • Facebook Page
  • Youtube Channel
  • Twitter
  • Exclusive Telegram Group
  • Discuss On WhatsApp Group