<div dir="ltr">David<br><br><div class="gmail_quote"><div dir="ltr">On Thu, Mar 10, 2016 at 1:15 AM Boldt, David <<a href="mailto:dboldt@usgs.gov">dboldt@usgs.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm not successful filtering on the connection state associated with a port.<br></blockquote><div><br></div><div>I couple of things to note, but first some explanation of how things work.  The STATE and PORT rules are matched against the text in the [ports] section of the client data, which is generally the output of "netstat -na" in one form or another, but including only TCP sockets.  The output of this command, and hence the required processing varies between operating systems, but in most cases the local IP and port is in column 3 (numbered from 0), the remote is in column 4 and the state is in column 5.  (The exceptions to this are Solaris, using columns 0, 1 and 6 respectively; and Windows which uses columns 1, 2 and 3.)</div><div><br></div><div>The output of "ss" is most definitely different to any "netstat" that I've seen.  In particular, the socket state is on column 0 - before either of the local or report addresses/ports.  It might be helpful to know what OS you're using, that doesn't have a netstat command.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
None of the syntax variations I have tried have been successful.<br>
If I remove the STATE specifier, matches are found.<br></blockquote><div><br></div><div>It's just a coincidence that the column numbers for local and remote are the same for netstat and ss.  Had this not been the case, you'd have had more trouble getting matches even with STATE unspecified.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I've set up several port monitoring specifications, but none of them<br>
match the state<br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
PORT LOCAL=%[:](61617) REMOTE=%10.160.8.133   STATE=ESTABLISHED MIN=3<br>
MAX=3 COLOR=yellow TEXT=ActiveMQ-nsp.er<br></blockquote><div><br></div><div>The normal "netstat" output uses the string "ESTABLISHED".  But "ss" uses "ESTAB".  If [ports] shows ESTAB then that's what you need to match.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
PORT LOCAL=%[:](61617) REMOTE=%136.177.16.3   STATE=ESTAB MIN=3 MAX=3<br>
COLOR=yellow TEXT=ActiveMQ-ns.cr<br></blockquote><div><br></div><div>Would work, if ESTAB was in the correct column.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
PORT LOCAL=%[:](61617) REMOTE=%137.227.240.32 STATE=%ESTAB MIN=3 MAX=3<br></blockquote><div><br></div><div>I think this will match only when the state starts and ends with "ESTAB" and so it'd probably work, provided the state was in the first column.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
COLOR=yellow TEXT=ActiveMQ-ns.er<br>
PORT LOCAL=%[:](61617) REMOTE=%130.118.4.2    STATE=%ESTAB* MIN=3<br>
MAX=3 COLOR=yellow TEXT=ActiveMQ-ns.wr<br></blockquote><div><br></div><div>The "%" marks the string that follows as a regular expression.  The asterisk in a regular expression means to match zero or more of the previous character.  So this would match "ESTAB" as well as "ESTA" and "ESTABB" and "ESTABBBBBB" but it wouldn't match "ESTABLISHED".</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Note: On this server netstat does not exist and ss is being used,.<br></blockquote><div><br></div><div>Yep, this is your problem.  I'm assuming that you edited the xymonclient-<os>.sh script and replaced "netstat -na" with "ss"?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Observation: Discovering the syntax for REMOTE was trial and error.<br>
Specifying the IP address alone did not work, and I found no examples<br>
for the type of filtering above.</blockquote><div><br></div><div>The analysis.cfg file has several examples for the use of LOCAL.  The REMOTE usage is the same.</div><div><br></div><div>So, what to do?  The simplest thing would be to adjust the output of "ss" so that the columns match up.  Simply replicating the state column would suffice.  Something like so:</div><div><br></div><div>ss -nt | awk '{ print $0 $1 }'</div><div><br></div><div>Cheers</div><div>Jeremy</div><div><br></div><div><br></div></div></div>