harv_ser.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. #!/bin/sh
  2. #
  3. # $Id$
  4. #
  5. # tool for post-processesing captured SIP messages
  6. #
  7. # call it without parameters to harvest the youngest
  8. # log file or with "all" parameter to harvest all
  9. #
  10. # you need to capture SIP messages first; you
  11. # may for example run an init.d job such as
  12. # ngrep -t port 5060 2>&1 | rotatelogs /var/log/sip 86400&
  13. # caution: if you do that you best set up a crond daemon
  14. # which deletes the files too -- they become huge
  15. # very quickly
  16. #
  17. # note that the tool has no notion of messages and transactions
  18. # yet; a consuquence of the former is that number of clients
  19. # which do not identify themselves using User-Agent HF is
  20. # unknown (only lines which include it are processed);
  21. # a consequence is also that relayed messages are
  22. # counted twice (incoming, outgoing), and INVITEs are not
  23. # correlated with BYEs
  24. #
  25. LOGDIR=/var/log
  26. #####################
  27. if [ "$1" = "all" ] ; then
  28. CURRENT=`ls -t $LOGDIR/sip.*`
  29. else
  30. CURRENT=`ls -t $LOGDIR/sip.* | head -1`
  31. fi
  32. echo "Log: `ls -l $CURRENT`"
  33. echo "Date: `date`"
  34. #cat $CURRENT | ./ser_harvest.awk
  35. AWK_PG='
  36. BEGIN {
  37. IGNORECASE=1;
  38. rpl100=0; rpl180=0; rpl183=0; rpl1xx=0;
  39. rpl200=0; rpl202=0; rpl2xx=0;
  40. rpl300=0; rpl302=0; rpl3xx=0;
  41. rpl400=0; rpl401=0; rpl403=0; rpl404=0; rpl405=0;
  42. rpl406=0;rpl407=0;rpl408=0;rpl410=0; rpl415=0;
  43. rpl476=0;rpl481=0;rpl483=0;rpl486=0;rpl478=0;rpl487=0;
  44. rpl488=0;rpl489=0;
  45. rpl4xx=0;
  46. rpl479=0;
  47. rpl500=0;rpl501=0;rpl502=0;rpl503=0;rpl5xx=0;
  48. rpl603=0;rpl6xx=0;
  49. hint_imgw=0;
  50. hint_voicemail=0;
  51. hint_battest=0;
  52. hint_usrloc=0;
  53. hint_outbound=0;
  54. hint_sms=0;
  55. hint_gw=0;
  56. hint_off_voicemail=0;
  57. cancel=0;invite=0;ack=0; info=0;register=0;bye=0;
  58. options=0;
  59. message=0; subscribe=0; notify=0;
  60. ua_snom=0;
  61. ua_msn=0;
  62. ua_mitel=0;
  63. ua_pingtel=0;
  64. ua_ser=0;
  65. ua_osip=0;
  66. ua_linphone=0;
  67. ua_kphone=0;
  68. ua_sjphone=0;
  69. ua_ubiquity=0;
  70. ua_3com=0;
  71. ua_ipdialog=0;
  72. ua_epygi=0;
  73. ua_jasomi=0;
  74. ua_cisco=0;
  75. ua_insipid=0;
  76. ua_hotsip=0;
  77. ua_mxsf=0;
  78. ua_grandstream=0;
  79. ua_tellme=0;
  80. ua_pocketsipm=0;
  81. ua_estara=0;
  82. ua_vovida=0;
  83. ua_jsip=0;
  84. ua_nortel=0;
  85. ua_polycom=0;
  86. ua_csco=0;
  87. ua_leader=0;
  88. ua_nebula=0;
  89. ua_yamaha=0;
  90. ua_magicppc=0;
  91. ua_scs=0;
  92. ua_edgeaccess=0;
  93. ua_tkc=0;
  94. ua_xx=0;
  95. server_cisco=0
  96. server_ser=0
  97. server_intertex=0
  98. server_hotsip=0
  99. server_3com=0
  100. server_epygi=0;
  101. server_leader=0;
  102. server_ims=0;
  103. server_csco=0;
  104. server_sapphire=0;
  105. server_lucent=0;
  106. server_snom=0;
  107. server_edgeaccess=0;
  108. server_mcet=0;
  109. server_xx=0
  110. }
  111. {ua=0; request=0;reply=0;server=0}
  112. ua==0 && /User-Agent:.*snom/ {
  113. ua_snom++
  114. ua=1
  115. }
  116. ua==0 && /User-Agent:.*tkcPhone/ {
  117. ua_tkc++
  118. ua=1
  119. }
  120. ua==0 && /User-Agent:.*Windows RTC/ {
  121. ua_msn++
  122. ua=1
  123. }
  124. ua==0 && /User-Agent:.*Mitel/ {
  125. ua_mitel++
  126. ua=1
  127. }
  128. ua==0 && /User-Agent:.*Pingtel/ {
  129. ua_pingtel++
  130. ua=1
  131. }
  132. ua==0 && /User-Agent:.*Sip EXpress/ {
  133. ua_ser++
  134. ua=1
  135. }
  136. ua==0 && /User-Agent:.*oSIP-ua/ {
  137. ua_osip++
  138. ua=1
  139. }
  140. ua==0 && /User-Agent:.*oSIP\/Linphone/ {
  141. ua_linphone++
  142. ua=1
  143. }
  144. ua==0 && /User-Agent:.*3Com/ {
  145. ua_3com++
  146. ua=1
  147. }
  148. ua==0 && /User-Agent:.*ipDialog/ {
  149. ua_ipdialog++
  150. ua=1
  151. }
  152. ua==0 && /User-Agent:.*UbiquityUserAgent/ {
  153. ua_ubiquity++
  154. ua=1
  155. }
  156. ua==0 && /User-Agent:.*EPYGI/ {
  157. ua_epygi++
  158. ua=1
  159. }
  160. ua==0 && /User-Agent:.*Jasomi/ {
  161. ua_jasomi++
  162. ua=1
  163. }
  164. ua==0 && /User-Agent:.*Cisco/ {
  165. ua_cisco++
  166. ua=1
  167. }
  168. ua==0 && /User-Agent:.*Insipid/ {
  169. ua_insipid++
  170. ua=1
  171. }
  172. ua==0 && /User-Agent:.*mxsf/ {
  173. ua_mxsf++
  174. ua=1
  175. }
  176. ua==0 && /User-Agent:.*Hotsip/ {
  177. ua_hotsip++
  178. ua=1
  179. }
  180. ua==0 && /User-Agent:.*GrandStream/ {
  181. ua_grandstream++
  182. ua=1
  183. }
  184. ua==0 && /User-Agent:.*Tellme/ {
  185. ua_tellme++
  186. ua=1
  187. }
  188. ua==0 && /User-Agent:.*PocketSipM/ {
  189. ua_pocketsipm++
  190. ua=1
  191. }
  192. ua==0 && /User-Agent:.*eStara/ {
  193. ua_estara++
  194. ua=1
  195. }
  196. ua==0 && /User-Agent:.*vovida/ {
  197. ua_vovida++
  198. ua=1
  199. }
  200. ua==0 && /User-Agent:.*jSIP/ {
  201. ua_jsip++
  202. ua=1
  203. }
  204. ua==0 && /User-Agent:.*Nortel/ {
  205. ua_nortel++
  206. ua=1
  207. }
  208. ua==0 && /User-Agent:.*Polycom/ {
  209. ua_polycom++
  210. ua=1
  211. }
  212. ua==0 && /User-Agent:.*CSCO/ {
  213. ua_csco++
  214. ua=1
  215. }
  216. ua==0 && /User-Agent:.*LeaderSIP/ {
  217. ua_leader++
  218. ua=1
  219. }
  220. ua==0 && /User-Agent:.*Nebula/ {
  221. ua_nebula++
  222. ua=1
  223. }
  224. ua==0 && /User-Agent:.*YAMAHA/ {
  225. ua_yamaha++
  226. ua=1
  227. }
  228. ua==0 && /User-Agent:.*MagicPPC/ {
  229. ua_magicppc++
  230. ua=1
  231. }
  232. ua==0 && /User-Agent:.*SJPhone/ {
  233. ua_sjphone++
  234. ua=1
  235. }
  236. ua==0 && /User-Agent:.*KPhone/ {
  237. ua_kphone++
  238. ua=1
  239. }
  240. ua==0 && /User-Agent:.*SCS/ {
  241. ua_scs++
  242. ua=1
  243. }
  244. ua==0 && /User-Agent:.*EdgEAccEss/ {
  245. ua_edgeaccess++
  246. ua=1
  247. }
  248. { comment="hack to deal with old version of ngrep (breaking in columns)"
  249. c="skip lines which words which frequently appeared on broken "
  250. c="columns. should not affect non-broken logs"
  251. }
  252. ua==0 && /(CANCEL|REGISTER|SUBSCRIBE|ACK|BYE|INVITE|REFER|OPTIONS|NOTIFY|sip-cc).*User-Agent:/ {
  253. ua=1
  254. }
  255. ua==0 && /User-Agent:/ {
  256. ua_xx++
  257. print
  258. }
  259. server==0 && /Server:.*Cisco/ {
  260. server_cisco++
  261. server=1
  262. }
  263. server==0 && /Server:.*Sip EXpress/ {
  264. server_ser++
  265. server=1
  266. }
  267. server==0 && /Server:.*Intertex/ {
  268. server_intertex++
  269. server=1
  270. }
  271. server==0 && /Server:.*HotSip/ {
  272. server_hotsip++
  273. server=1
  274. }
  275. server==0 && /Server:.*3Com/ {
  276. server_3com++
  277. server=1
  278. }
  279. server==0 && /Server:.*EPYGI/ {
  280. server_epygi++
  281. server=1
  282. }
  283. server==0 && /Server:.*LeaderSIP_UA/ {
  284. server_leader++
  285. server=1
  286. }
  287. server==0 && /Server:.*IMS/ {
  288. server_ims++
  289. server=1
  290. }
  291. server==0 && /Server:.*CSCO/ {
  292. server_csco++
  293. server=1
  294. }
  295. server==0 && /Server:.*sapphire/ {
  296. server_sapphire++
  297. server=1
  298. }
  299. server==0 && /Server:.*snom/ {
  300. server_snom++
  301. server=1
  302. }
  303. server==0 && /Server:.*Lucent/ {
  304. server_lucent++
  305. server=1
  306. }
  307. server==0 && /Server:.*EdgEAccEss/ {
  308. server_edgeaccess++
  309. server=1
  310. }
  311. server==0 && /Server:.*MCET/ {
  312. server_mcet++
  313. server=1
  314. }
  315. server==0 && /Server:/ {
  316. server_xx++
  317. print
  318. }
  319. /P-hint: IMGW/ {
  320. hint_imgw++
  321. }
  322. /P-hint: VOICEMAIL/ {
  323. hint_voicemail++
  324. }
  325. /P-hint: BATTEST/ {
  326. hint_battest++
  327. }
  328. /P-hint: USRLOC/ {
  329. hint_usrloc++
  330. }
  331. /P-hint: OUTBOUND/ {
  332. hint_outbound++
  333. }
  334. /P-hint: SMS/ {
  335. hint_sms++
  336. }
  337. /P-hint: GATEWAY/ {
  338. hint_gw++
  339. }
  340. /P-hint: OFFLINE-VOICEMAIL/ {
  341. hint_off_voicemail++
  342. }
  343. /SIP\/2\.0 [0-9][0-9][0-9]/ {
  344. reply=1
  345. }
  346. /[A-Z]* sip.* SIP\/2\.0/ {
  347. request=1
  348. }
  349. reply==0 && request=0 {
  350. comment="optimization--skip now"
  351. next
  352. }
  353. /SIP\/2\.0 100/ {
  354. rpl100++
  355. next
  356. }
  357. /SIP\/2\.0 180/ {
  358. rpl180++
  359. next
  360. }
  361. /SIP\/2\.0 183/ {
  362. rpl183++
  363. next
  364. }
  365. /SIP\/2\.0 1[0-9][0-9]/ {
  366. print
  367. rpl1xx=0
  368. next
  369. }
  370. /SIP\/2\.0 200/ {
  371. rpl200++
  372. next
  373. }
  374. /SIP\/2\.0 202/ {
  375. rpl202++
  376. next
  377. }
  378. /SIP\/2\.0 2[0-9][0-9]/ {
  379. print
  380. rpl2xx++
  381. next
  382. }
  383. /SIP\/2\.0 300/ {
  384. rpl300++
  385. next
  386. }
  387. /SIP\/2\.0 302/ {
  388. rpl302++
  389. next
  390. }
  391. /SIP\/2\.0 3[0-9][0-9]/ {
  392. print
  393. rpl3xx++
  394. next
  395. }
  396. /SIP\/2\.0 400/ {
  397. rpl400++
  398. next
  399. }
  400. /SIP\/2\.0 401/ {
  401. rpl401++
  402. next
  403. }
  404. /SIP\/2\.0 403/ {
  405. rpl403++
  406. next
  407. }
  408. /SIP\/2\.0 404/ {
  409. rpl404++
  410. next
  411. }
  412. /SIP\/2\.0 405/ {
  413. rpl405++
  414. next
  415. }
  416. /SIP\/2\.0 406/ {
  417. rpl406++
  418. next
  419. }
  420. /SIP\/2\.0 407/ {
  421. rpl407++
  422. next
  423. }
  424. /SIP\/2\.0 408/ {
  425. rpl408++
  426. next
  427. }
  428. /SIP\/2\.0 410/ {
  429. rpl410++
  430. next
  431. }
  432. /SIP\/2\.0 415/ {
  433. rpl415++
  434. next
  435. }
  436. /SIP\/2\.0 478/ {
  437. rpl478++
  438. next
  439. }
  440. /SIP\/2\.0 476/ {
  441. rpl476++
  442. next
  443. }
  444. /SIP\/2\.0 481/ {
  445. rpl481++
  446. next
  447. }
  448. /SIP\/2\.0 483/ {
  449. rpl483++
  450. next
  451. }
  452. /SIP\/2\.0 486/ {
  453. rpl486++
  454. next
  455. }
  456. /SIP\/2\.0 487/ {
  457. rpl487++
  458. next
  459. }
  460. /SIP\/2\.0 488/ {
  461. rpl488++
  462. next
  463. }
  464. /SIP\/2\.0 489/ {
  465. rpl489++
  466. next
  467. }
  468. /SIP\/2\.0 479/ {
  469. rpl479++
  470. next
  471. }
  472. /SIP\/2\.0 4[0-9][0-9]/ {
  473. print
  474. rpl4xx++
  475. next
  476. }
  477. /SIP\/2\.0 500/ {
  478. rpl500++
  479. next
  480. }
  481. /SIP\/2\.0 501/ {
  482. rpl501++
  483. next
  484. }
  485. /SIP\/2\.0 502/ {
  486. rpl502++
  487. next
  488. }
  489. /SIP\/2\.0 503/ {
  490. rpl503++
  491. next
  492. }
  493. /SIP\/2\.0 5[0-9][0-9]/ {
  494. print
  495. rpl5xx++
  496. next
  497. }
  498. /SIP\/2\.0 603/{
  499. rpl603++
  500. next
  501. }
  502. /SIP\/2\.0 6[0=9][0-9]/ {
  503. print
  504. rpl6xx++
  505. next
  506. }
  507. /CANCEL sip/ {
  508. cancel++
  509. next
  510. }
  511. /INVITE sip/ {
  512. invite++
  513. next
  514. }
  515. /ACK sip/ {
  516. ack++
  517. next
  518. }
  519. /BYE sip/ {
  520. bye++
  521. next
  522. }
  523. /OPTIONS sip/ {
  524. options++
  525. next
  526. }
  527. /INFO sip/ {
  528. info++
  529. next
  530. }
  531. /MESSAGE sip/ {
  532. message++
  533. next
  534. }
  535. /SUBSCRIBE sip/ {
  536. subscribe++
  537. next
  538. }
  539. /NOTIFY sip/ {
  540. notify++
  541. next
  542. }
  543. /REGISTER sip/ {
  544. register++
  545. next
  546. }
  547. END {
  548. print "## Reply Codes"
  549. print "100 (trying): " rpl100
  550. print "180 (ringing): " rpl180
  551. print "183: (early media)" rpl183
  552. print "1xx: " rpl1xx
  553. print "200 (ok): " rpl200
  554. print "202 (accepted): " rpl202
  555. print "2xx: " rpl2xx
  556. print "300 (Multiple Choices): " rpl300
  557. print "302 (Moved Temporarily): " rpl302
  558. print "3xx: " rpl3xx
  559. print "400 (Bad Request): " rpl400
  560. print "401 (Unauthorized): " rpl401
  561. print "403 (Forbidden): " rpl403
  562. print "404 (Not Found):" rpl404
  563. print "405 (Method not allowed): " rpl405
  564. print "406 (Not Acceptable): " rpl406
  565. print "407 (Proxy Authentication Required):" rpl407
  566. print "408 (Request Timeout): " rpl408
  567. print "410 (Gone): " rpl410
  568. print "415 (Unsupported Media): " rpl415
  569. print "476 (no recursive registrations): " rpl476
  570. print "478 (Unresolveable): " rpl478
  571. print "479 (private IP): " rpl479
  572. print "481 (Call/Transaction does not exist): " rpl481
  573. print "483 (Too Many Hops): " rpl483
  574. print "486 (Busy Here): " rpl486
  575. print "487 (Request Terminated): " rpl487
  576. print "488 (Not Acceptable): " rpl488
  577. print "489 (Bad Event): " rpl489
  578. print "4xx: " rpl4xx
  579. print "500 (Server Internal Error): " rpl500
  580. print "501 (Not Implemented): " rpl501
  581. print "502 (Bad Gateway): " rpl502
  582. print "503 (Service Unavailabl): " rpl503
  583. print "5xx: " rpl5xx
  584. print "603 (Decline): " rpl603
  585. print "6xx: " rpl6xx
  586. print "## Request Methods"
  587. print "INVITE: " invite " CANCEL: " cancel " ACK: " ack
  588. print "REGISTER: " register " BYE: " bye " OPTIONS: " options " INFO: " info
  589. print "MESSAGE: " message " SUBSCRIBE: " subscribe " NOTIFY: " notify
  590. print "## Outbound Routes"
  591. print "To imgw: " hint_imgw " To voicemail: " hint_voicemail
  592. print "To bat: " hint_battest " To UsrLoc: " hint_usrloc
  593. print "Outbound: " hint_outbound " To SMS: " hint_sms
  594. print "To PSTN: " hint_gw " To: VM on off-line" hint_off_voicemail
  595. print "## User Agents"
  596. print "Snom: " ua_snom " MSN: " ua_msn " Mitel: " ua_mitel
  597. print "Pingtel: " ua_pingtel " SER: " ua_ser " osip: " ua_osip
  598. print "linphone: " ua_linphone " ubiquity: " ua_ubiquity
  599. print "3com: " ua_3com " IPDialog: " ua_ipdialog " Epygi: " ua_epygi
  600. print "Jasomi: " ua_jasomi " Cisco: " ua_cisco " insipid: " ua_insipid
  601. print "Hotsip: " ua_hotsip " mxsf: " ua_mxsf " GrandStream: " ua_grandstream
  602. print "Tellme: " ua_tellme " PocketSipM: " ua_pocketsipm
  603. print "eStara: " ua_estara " Vovida: " ua_vovida
  604. print "jSIP: " ua_jsip " Nortel: " ua_nortel " Polycom: " ua_polycom
  605. print "Leader: " ua_leader " csco: " ua_csco " Nebula: " ua_nebula
  606. print "MagicPPC: " ua_magicppc " SCS: " ua_scs
  607. print "SJPhone: " ua_sjphone " KPhone: " ua_kphone
  608. print "Yamaha: " ua_yamaha
  609. print "tkcPhone: " ua_tkc
  610. print "EdgeAccess: " ua_edgeaccess
  611. print "UFO: " ua_xx
  612. print "## Servers"
  613. print "Cisco: " server_cisco " ser: " server_ser
  614. print "Intertex: " server_intertex " Hotsip: " server_hotsip
  615. print "3com: " server_3com " EPYGI: " server_epygi " Leader: " server_leader
  616. print "IMS (Nortel): " server_ims " CSCO: " server_csco
  617. print "sapphire: " server_sapphire
  618. print "snom: " server_snom
  619. print "lucent: " server_lucent
  620. print "edgeAccess: " server_edgeaccess
  621. print "mcet: " server_mcet
  622. print "UFO: " server_xx
  623. }
  624. '
  625. cat $CURRENT | awk "$AWK_PG"