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 <[email protected]>
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 [email protected] 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 ${#inactiveAccounts[@]} inactive accounts: "
> for _user in ${inactiveAccounts[@]}; 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 [ "${#inactiveAccounts[@]}" -eq "0" ]; then
>   exit 0
> elif (( "${#inactiveAccounts[@]}" >= "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
>



-- 

*Geoff GoasSystems Engineer*
--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general

Reply via email to