Thank you for the quick turnaround, I will give it a shot and let you know how it works out, we need it for Citrix and want to make sure no fewer than 5 are logged in to any one machine.<br><br><div class="gmail_quote">On Tue, Nov 13, 2012 at 11:22 AM, Henrik Størner <span dir="ltr"><<a href="mailto:henrik@hswn.dk" target="_blank">henrik@hswn.dk</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 13-11-2012 16:05, Ray Reuter wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I need to be able to alert off of the "who" column. An example would be<br>
if there was less than 5 connections I would like to be alerted. I know<br>
way back in Big Brother days there was a perl script to do just that but<br>
I am having zero luck of finding it now.<br>
</blockquote>
<br></div>
First step is to make the "who" status red - if you do that, then you can use the normal alert-rules to send out alerts.<br>
<br>
Current Xymon versions allow you to modify the color of an existing status, by sending a "modify" command to xymond. So what I would do was to run a script on the Xymon server which regularly fetches all of the "who" statuses, counts how many users are logged in on each host, and the sends a "modify" status if the maximum is exceeded.<br>


<br>
<br>
To get all of the "who" statuses, you can use<br>
        xymon 127.0.0.1 "xymondboard test=who fields=hostname,msg"<br>
The output from this command is one line per status, with the hostname, then a '|' delimiter, and then the status-message with new-line changed into '\n'. I'm sure someone with Perl / Python / whatever scripting knowledge could easily turn this into something where you could count the number of lines (one for each user, minus a couple of header-lines), but here's a C program that will do it:<br>


<br>
--- cut here ---<br>
#include <stdio.h><br>
#include <string.h><br>
#include <stdlib.h><br>
<br>
int main(int argc, char **argv)<br>
{<br>
        char buf[4096];<br>
        char *hostname, *msg, *l_start, *l_end;<br>
<br>
        while (fgets(buf, sizeof(buf), stdin)) {<br>
                int loggedin = 0;<br>
<br>
                hostname = strtok(buf, "|");<br>
                msg = strtok(NULL, "\n");<br>
                if (!msg) continue;<br>
<br>
                l_start = msg;<br>
                do {<br>
                        l_end = strstr(l_start, "\\n");<br>
<br>
                        if ( (strncmp(l_start, "SESSIONNAME", 11) == 0) ||<br>
                             (strncmp(l_start, ">", 1) == 0) ||<br>
                             (strncmp(l_start, "rdp-tcp", 7) == 0) ||<br>
                             (strncmp(l_start, "console", 7) == 0) ) {<br>
                                /* Ignore the line */<br>
                        }<br>
                        else {<br>
                                loggedin++;<br>
                        }<br>
<br>
                        l_start = l_end ? (l_end + 2) : NULL;<br>
                } while (l_start);<br>
<br>
                fprintf(stdout, "%s %d\n", hostname, loggedin);<br>
        }<br>
<br>
        return 0;<br>
}<br>
--- cut here ---<br>
<br>
Just save this to "whocount.c" and run "gcc -o whocount whocount.c" to compile it. It ignores lines beginning with the texts "SESSIONNAME", ">", "rdp-tcp" or "console" - I think those lines always appear in the "who" status regardless of who is logged in.<br>


<br>
When you feed the input from the xymondboard command into this, it should output one line for each host with the hostname and the number of users logged in.<br>
<br>
So putting it all together, this script will change the "who" status to red for all hosts where 5 or more users are logged in:<br>
<br>
--- cut here ---<br>
#!/bin/sh<br>
<br>
LIMIT=5<br>
<br>
xymon 127.0.0.1 "xymondboard test=who fields=hostname,msg" | whocount | while read L<br>
do<br>
    set $L<br>
    HOSTNAME=$1<br>
    LOGINCOUNT=$2<br>
<br>
    if test $LOGINCOUNT -gt $LIMIT<br>
    then<br>
        echo 127.0.0.1 "modify $HOSTNAME.who red whomon $LOGINCOUNT users logged in (max is $LIMIT)"<br>
    fi<br>
done<br>
<br>
exit 0<br>
--- cut here ---<br>
<br>
(assumes the "whocount" utility is in your PATH).<br>
<br>
You'd run this as an extra task from tasks.cfg - e.g. every 5 minutes.<br>
<br>
<br>
Now you have the "who" status going red when too many users are logged in, so alerting is easy - just add<br>
<br>
TEST=who COLOR=red<br>
        MAIL <a href="mailto:security@example.com" target="_blank">security@example.com</a><br>
<br>
to alerts.cfg .<br>
<br>
<br>
Regards,<br>
Henrik<br>
<br>
</blockquote></div><br>