[Top][All Lists]

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

Re: Question about script alert description

From: Bryan Harris
Subject: Re: Question about script alert description
Date: Mon, 12 Sep 2016 16:32:29 -0400

Sure we could do that.  It's just that we went with monit for our monitoring (for the most part).  It may not be that big of a concern, just seems like it would be nice to have our script output as the full description message.  Then any old script could perform any old monit check and there would be no difference (in output message style).  As it is, the script output has to fight with monit's extra message for space in the email (if you want it all on one line).  I guess I could throw a newline in there to have it on the next line.  I guess I just don't see any need for forcing that message.  If I want to know the return code I could print it with my script.

Thanks for the feed back though.  I wonder if they will tell me to just go with cron.


On Mon, Sep 12, 2016 at 4:23 PM, Geoff Goas <address@hidden> wrote:
This doesn't answer your question, but is running the script from cron and having it send the email notification not an option?

On Mon, Sep 12, 2016 at 7:50 AM, 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/' failed with exit status (1) -- 3 inactive accounts: *user1, user2, *user3

Monit adds this extra line: '/usr/local/sbin/' 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/"
  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.


# 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

# Create a printout suitable for Monit reporting
printf "Found address@hidden inactive accounts: "
for _user in address@hidden; do
  if (("$_i" > "0")); then
    printf ","
  printf "$_user"
  (( _i += 1 ))
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

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


To unsubscribe:

Geoff Goas
Systems Engineer

To unsubscribe:

reply via email to

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