monit-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about script alert description


From: Martin Pala
Subject: Re: Question about script alert description
Date: Tue, 13 Sep 2016 09:29:11 +0200

Hi,

the prefix "'/usr/local/sbin/inactive.sh' failed with exit status (1) -- " is part of the event description. We can simplify that message, the program path is not necessary as service name is reported too, but the status value should still be part of the event description.

Best regards,
Martin



On 12 Sep 2016, at 13:50, Bryan Harris <address@hidden> wrote:

Hi folks,

I have recently created a script to figure out which users on the local system have expired accounts.  So anyone returned by the script output will be a user account that is expired and can't login.  And if they have a star (*) by their name the account is older than 90 days.

When I get back the alert email, the description not only has my script output but it also contains its own little info line.

My script output is just:

3 inactive accounts: *user1, user2, *user3

But When I get an alert it looks like this:

Description: '/usr/local/sbin/inactive.sh' failed with exit status (1) -- 3 inactive accounts: *user1, user2, *user3

Monit adds this extra line: '/usr/local/sbin/inactive.sh' failed with exit status (1) --

Does anyone know how to instruct Monit to exclude this line from the $DESCRIPTION field?  I just want the output like this:

Description: 3 inactive accounts: *user1, user2, *user3

Here is the way I have entered configuration declaration into Monit.

check program inactive-accounts with path "/usr/local/sbin/inactive.sh"
  every "0-3 6 * * *"
  alert address@hidden not on { instance, action }
  if status != 0 then alert

# vim: ft=config

I'm running monit from EPEL and the version is: monit-5.14-1.el6.x86_64.

I don't suppose it matters a lot, but just in case, here is the script.

#!/bin/bash

# Let's get a list of accounts likely to be people, not service accounts
_accounts=`getent --service=files passwd | awk -F: '$3 > 500 && $1 !~ /splunk|service|oracle|nobody|nails/'`

# What to call the array of inactive accounts
declare -a inactiveAccounts

# Today's date
_todaysDateInDaysSince1970=`echo \`date +%s\`/86400 | bc`

# Now let's see who's account is inactive, and add it to the array
for _row in $_accounts ; do
  _user=`echo $_row | awk -F: '{print $1}'`
  _accountExpirationInDaysSince1970=`getent --service=files shadow $_user | awk -F: '{print $8}'`
  if (("$_todaysDateInDaysSince1970" > "$_accountExpirationInDaysSince1970")); then
    if (("$(($_todaysDateInDaysSince1970-$_accountExpirationInDaysSince1970))" > "90")); then
      inactiveAccounts+=("*$_user")
    else
      inactiveAccounts+=("$_user")
    fi
  fi
done

# Create a printout suitable for Monit reporting
_i=0
printf "Found address@hidden inactive accounts: "
for _user in address@hidden; do
  if (("$_i" > "0")); then
    printf ","
  fi
  printf "$_user"
  (( _i += 1 ))
done
printf "\n"

# Exit code of 0 for Success (no inactive accounts)
# Exit code of 1 for Alert (inactive accounts)
if [ "address@hidden" -eq "0" ]; then
  exit 0
elif (( "address@hidden" >= "1" )); then
  exit 1
fi


Thanks in advance for any hint or info in the right direction.

V/r,
Bryan

--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general


reply via email to

[Prev in Thread] Current Thread [Next in Thread]