Jelajahi Sumber

hit and UA counting added

Jiri Kuthan 23 tahun lalu
induk
melakukan
34b64c0ce2
1 mengubah file dengan 175 tambahan dan 8 penghapusan
  1. 175 8
      scripts/harv_ser.sh

+ 175 - 8
scripts/harv_ser.sh

@@ -2,14 +2,25 @@
 #
 # $Id$
 #
-# collect SIP message dump statistics
+# tool for post-processesing captured SIP messages 
 #
 # call it without parameters to harvest the youngest
 # log file or with "all" parameter to harvest all
 # 
-# (you need to capture SIP messages first; you
+# you need to capture SIP messages first; you
 # may for example run an init.d job such as
 # ngrep -t port 5060 2>&1 | rotatelogs /var/log/sip 86400&
+# caution: if you do that you best set up a crond daemon
+# which deletes the files too -- they become huge
+# very quickly
+#
+# note that the tool has no notion of messages and transactions
+# yet; a consuquence of the former is that number of clients
+# which do not identify themselves using User-Agent HF is 
+# unknown (only lines which include it are processed);
+# a consequence is also that relayed messages are
+# counted twice (incoming, outgoing), and INVITEs are not
+# correlated with BYEs
 #
 
 
@@ -20,7 +31,7 @@ LOGDIR=/var/log
 if [ "$1" = "all" ] ; then
 	CURRENT=`ls -t $LOGDIR/sip.*`
 else
-	CURRENT=`ls -t $LOGDIR/sip.* | tail -1`
+	CURRENT=`ls -t $LOGDIR/sip.* | head -1`
 fi
 echo "Log: $CURRENT"
 
@@ -35,15 +46,149 @@ BEGIN {
         rpl407=0;rpl408=0;rpl410=0;
         rpl481=0;rpl486=0;rpl487=0;
         rpl4xx=0;
-    rpl500=0;rpl5xx=0;
-    rpl6xx=0;
+    rpl500=0;rpl501=0;rpl5xx=0;
+    rpl603=0;rpl6xx=0;
+
+	hint_imgw=0;
+	hint_voicemail=0;
+	hint_battest=0;
+	hint_usrloc=0;
+	hint_outbound=0;
+	hint_sms=0;
+	hint_gw=0;
+	hint_off_voicemail=0;
 
 
     cancel=0;invite=0;ack=0; info=0;register=0;bye=0;
     options=0;
     message=0; subscribe=0; notify=0;
+
+	ua_snom=0;
+	ua_msn=0;
+	ua_mitel=0;
+	ua_pingtel=0;
+	ua_ser=0;
+	ua_osip=0;
+	ua_linphone=0;
+	ua_ubiquity=0;
+	ua_3com=0;
+	ua_ipdialog=0;
+	ua_epygi=0;
+	ua_jasomi=0;
+	ua_cisco=0;
+	ua_insipid=0;
+	ua_hostip=0;
+	ua_xx=0;
+
+	ua=0;
+}
+
+{ua=0}
+
+ua==0 && /User-Agent:.*snom/ {
+	ua_snom++
+	ua=1
+}
+ua==0 && /User-Agent:.*Windows RTC/ {
+	ua_msn++
+	ua=1
+}
+ua==0 && /User-Agent:.*Mitel/ {
+	ua_mitel++
+	ua=1
+}
+ua==0 && /User-Agent:.*Pingtel/ {
+	ua_pingtel++
+	ua=1
+}
+ua==0 && /User-Agent:.*Sip EXpress/ {
+	ua_ser++
+	ua=1
+}
+ua==0 && /User-Agent:.*oSIP-ua/ {
+	ua_osip++
+	ua=1
+}
+ua==0 && /User-Agent:.*oSIP\/Linphone/ {
+	ua_linphone++
+	ua=1
+}
+ua==0 && /User-Agent:.*3Com/ {
+	ua_3com++
+	ua=1
+}
+ua==0 && /User-Agent:.*ipDialog/ {
+	ua_ipdialog++
+	ua=1
+}
+ua==0 && /User-Agent:.*UbiquityUserAgent/ {
+	ua_ubiquity++
+	ua=1
+}
+ua==0 && /User-Agent:.*EPYGI/ {
+	ua_epygi++
+	ua=1
+}
+ua==0 && /User-Agent:.*Jasomi/ {
+	ua_jasomi++
+	ua=1
+}
+ua==0 && /User-Agent:.*Cisco/ {
+	ua_cisco++
+	ua=1
+}
+ua==0 && /User-Agent:.*Insipid/ {
+	ua_insipid++
+	ua=1
+}
+ua==0 && /User-Agent:.*Hotsip/ {
+	ua_hotsip++
+	ua=1
 }
 
+ { comment="hack to deal with old version of ngrep (breaking in columns)"
+		 c="skip lines which words which frequently appeared on broken "
+		 c="columns. should not affect non-broken logs"
+ }
+
+
+ua==0 && /(CANCEL|REGISTER|SUBSCRIBE|ACK|BYE|INVITE|REFER|OPTIONS|NOTIFY|sip-cc).*User-Agent:/ {
+	ua=1
+}
+
+ua==0 && /User-Agent:/ {
+	ua_xx++
+	print
+}
+
+
+
+/P-hint: IMGW/ {
+	hint_imgw++
+}
+/P-hint: VOICEMAIL/ {
+	hint_voicemail++
+}
+/P-hint: BATTEST/ {
+	hint_battest++
+}
+/P-hint: USRLOC/ {
+	hint_usrloc++
+}
+/P-hint: OUTBOUND/ {
+	hint_outbound++
+}
+/P-hint: SMS/ {
+	hint_sms++
+}
+/P-hint: GATEWAY/ {
+	hint_gw++
+}
+/P-hint: OFFLINE-VOICEMAIL/ {
+	hint_off_voicemail++
+}
+
+
 /SIP\/2\.0 100/ {
     rpl100++
     next
@@ -146,12 +291,20 @@ BEGIN {
     rpl500++
     next
 }
+/SIP\/2\.0 501/ {
+    rpl501++
+    next
+}
 /SIP\/2\.0 5[0-9][0-9]/ {
     print
     rpl5xx++
     next
 }
 
+/SIP\/2\.0 603/{
+	rpl603++
+	next
+}
 /SIP\/2\.0 6[0=9][0-9]/ {
     print
     rpl6xx++
@@ -197,7 +350,8 @@ BEGIN {
 }
 
 END {
-    print "100: " rpl100 " 180: " rpl100 " 1xx: " rpl1xx
+	print "## Reply Codes"
+    print "100: " rpl100 " 180: " rpl180 " 183: " rpl183 " 1xx: " rpl1xx
     print "200: " rpl200 " 202: " rpl202 " 2xx: " rpl2xx
     print "300: " rpl300 " 302: " rpl302 " 3xx: " rpl3xx
     print "400: " rpl400 " 401: " rpl401 " 403: " rpl403 
@@ -205,11 +359,24 @@ END {
         " 407: " rpl407 " 408: " rpl408  " 410: " rpl410
         " 481: " rpl481 " 486: " rpl486 " 487: " rpl487
         " 4xx: " rpl4xx  " 3xx: " rpl3xx
-    print "500: " rpl500 " 5xx: " rpl5xx
-    print "6xx: " rpl6xx
+    print "500: " rpl500 " 501: " rpl501 " 5xx: " rpl5xx
+    print "603: " rpl603 " 6xx: " rpl6xx
+	print "## Request Methods"
     print "INVITE: " invite " CANCEL: " cancel " ACK: " ack
     print "BYE: " bye " OPTIONS: " options " INFO: " info
     print "MESSAGE: " message " SUBSCRIBE: " subscribe " NOTIFY: " notify
+	print "## Outbound Routes"
+	print "To imgw: " hint_imgw " To voicemail: " hint_voicemail
+	print "To bat: " hint_battest " To UsrLoc: " hint_usrloc
+	print "Outbound: " hint_outbound " To SMS: " hint_sms
+	print "To PSTN: " hint_gw " To: VM on off-line" hint_off_voicemail
+	print "## User Agents"
+	print "Snom: " ua_snom " MSN: " ua_msn " Mitel: " ua_mitel
+	print "Pingtel: " ua_pingtel " SER: " ua_ser " osip: " ua_osip
+	print "linphone: " ua_linphone " ubiquity: " ua_ubiquity
+	print "3com: " ua_3com " IPDialog: " ua_ipdialog " Epygi: " ua_epygi
+	print "Jasomi: " ua_jasomi " Cisco: " ua_cisco " insipid: " ua_insipid
+	print "Hotsip: " ua_hotsip " UFO: " ua_xx
 }
 '