{"id":12204,"date":"2022-03-24T17:27:40","date_gmt":"2022-03-24T12:27:40","guid":{"rendered":"https:\/\/alexeyka.zantsev.com\/?p=12204"},"modified":"2022-03-24T23:04:09","modified_gmt":"2022-03-24T18:04:09","slug":"opensips-monitoring-with-zabbix-http-agent-jsonpath","status":"publish","type":"post","link":"https:\/\/alexeyka.zantsev.com\/?p=12204","title":{"rendered":"OpenSIPS: monitoring with Zabbix: HTTP Agent, JSONPath"},"content":{"rendered":"\n<p>This guide will help you to understand how OpenSIPS can be monitored with Zabbix, sharing its statistic data via HTTP interface in JSON format. This article assumes using <a href=\"https:\/\/www.opensips.org\/Documentation\/Manual-3-2\" data-type=\"URL\" data-id=\"https:\/\/www.opensips.org\/Documentation\/Manual-3-2\" target=\"_blank\" rel=\"noreferrer noopener\">OpenSIPS 3.2<\/a> and <a href=\"https:\/\/www.zabbix.com\/documentation\/6.0\/en\/manual\" target=\"_blank\" rel=\"noreferrer noopener\">Zabbix 6<\/a>.<\/p>\n\n\n\n<p>Enable <a href=\"https:\/\/opensips.org\/docs\/modules\/3.2.x\/httpd.html\" data-type=\"URL\" data-id=\"https:\/\/opensips.org\/docs\/modules\/3.2.x\/httpd.html\" target=\"_blank\" rel=\"noreferrer noopener\">embedded HTTP server<\/a>&nbsp;and <a href=\"https:\/\/opensips.org\/docs\/modules\/3.2.x\/mi_http.html\" data-type=\"URL\" data-id=\"https:\/\/opensips.org\/docs\/modules\/3.2.x\/mi_http.html\" target=\"_blank\" rel=\"noreferrer noopener\">HTTP support for Management Interface<\/a> in your OpenSIPS:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-red-color has-text-color\">loadmodule \"httpd.so\"\nmodparam(\"httpd\", \"ip\", \"192.168.88.244\")\nmodparam(\"httpd\", \"port\", 8888)\n\n# :8888\/mi\nloadmodule \"mi_http.so\"\nmodparam(\"mi_http\", \"root\", \"mi\")<\/pre>\n\n\n\n<p>Now we may try to send a JSON-RPC OpenSIPS MI command from the command-line, using&nbsp;curl (<a rel=\"noreferrer noopener\" href=\"https:\/\/www.opensips.org\/Documentation\/Interface-MI-3-2\" target=\"_blank\">official example<\/a> at the very bottom of the page):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-red-color has-text-color\">\/usr\/bin\/curl -X POST 192.168.88.244:8888\/mi -H 'Content-Type: application\/json' -d '{\"jsonrpc\": \"2.0\", \"id\": \"1\", \"method\": \"uptime\"}'<\/pre>\n\n\n\n<p>The official documentation does not have other more complicated examples, e.g. &#8220;get_statistics sl:&#8221;, that&#8217;s why I decided to write this article, maybe it&#8217;s more about JSON, JSONPath and working with all this in Zabbix.<\/p>\n\n\n\n<p>As an example, we&#8217;ll get stateless replier module <a rel=\"noreferrer noopener\" href=\"https:\/\/opensips.org\/docs\/modules\/3.2.x\/sl.html#idp5574016\" data-type=\"URL\" data-id=\"https:\/\/opensips.org\/docs\/modules\/3.2.x\/sl.html#idp5574016\" target=\"_blank\">statistics<\/a>, like shown by invoking a CLI command &#8220;opensips-cli -x mi get_statistics sl:&#8221; . <\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-red-color has-text-color\">\/usr\/bin\/curl -X POST 192.168.88.244:8888\/mi -H 'Content-Type: application\/json' -d '{\"jsonrpc\": \"2.0\", \"id\": \"1\", \"method\": \"get_statistics\", \"params\": {\"statistics\": [\"sl:\"]}}'<\/pre>\n\n\n\n<p>I&#8217;ll also duplicate the command with a screenshot (to be sure that you see it in a right way, because markup may cut some special characters):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized is-style-default\"><a href=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj1-1024x17.png\" alt=\"\" class=\"wp-image-12206\" width=\"768\" height=\"13\" srcset=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj1-1024x17.png 1024w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj1-300x5.png 300w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj1-768x13.png 768w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj1-1536x26.png 1536w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj1.png 1541w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/figure>\n\n\n\n<p>Tip: if you need statistics from several groups, for example several modules (not only SL), the request will be as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-red-color has-text-color\">\/usr\/bin\/curl -X POST 192.168.88.244:8888\/mi -H 'Content-Type: application\/json' -d '{\"jsonrpc\": \"2.0\", \"id\": \"1\", \"method\": \"get_statistics\", \"params\": {\"statistics\": [\"sl:\", \"tm:\"]}}'<\/pre>\n\n\n\n<p>OpenSIPS will answer and you&#8217;ll see SL module statistics after sending this request with CURL.<\/p>\n\n\n\n<p>But the responce is a one-liner, so we need to convert this one line to JSON format and then to create a JSONPath, to be able to extract the value we need.<\/p>\n\n\n\n<p>Let&#8217;s monitor not all SL module statistics received from OpenSIPS, but <em>the number of 2xx replies<\/em> only.<\/p>\n\n\n\n<p>I use <a rel=\"noreferrer noopener\" href=\"https:\/\/www.jsonformatter.io\/\" target=\"_blank\">https:\/\/www.jsonformatter.io\/<\/a> for JSON formatting and <a rel=\"noreferrer noopener\" href=\"https:\/\/jsonpath.com\/\" target=\"_blank\">https:\/\/jsonpath.com\/<\/a> for creating JSONPath. After formatting and specifying JSONPath we can configure Zabbix.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Now it&#8217;s time to add items to your OpenSIPS host in Zabbix. Item parameters:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-red-color has-text-color\">Type: HTTP Agent\nType of information: Numeric (unsigned)\nRequest type: POST\nRequest body type: JSON data\nRequest body: {\"jsonrpc\": \"2.0\", \"id\": \"1\", \"method\": \"get_statistics\", \"params\": {\"statistics\": [\"sl:\"]}}\nRetrieve mode: Body\nConvert to JSON (enabled)\n<\/pre>\n\n\n\n<p>Screenshots as usual:<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj2.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"921\" height=\"740\" data-id=\"12212\" src=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj2.png\" alt=\"\" class=\"wp-image-12212\" srcset=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj2.png 921w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj2-300x241.png 300w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj2-768x617.png 768w\" sizes=\"auto, (max-width: 921px) 100vw, 921px\" \/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj3.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"939\" height=\"890\" data-id=\"12213\" src=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj3.png\" alt=\"\" class=\"wp-image-12213\" srcset=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj3.png 939w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj3-300x284.png 300w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj3-768x728.png 768w\" sizes=\"auto, (max-width: 939px) 100vw, 939px\" \/><\/a><\/figure>\n<\/figure>\n<\/div><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Item Preprocessing parameters:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-red-color has-text-color\">1st step - JSONPath\nParameters: $.body.result.[\"sl:2xx_replies\"]\nType of information: Numeric (unsigned)<\/pre>\n\n\n\n<p>Screen &#8211; item Preprocessing and successful testing:<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj4.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1222\" height=\"308\" data-id=\"12214\" src=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj4.png\" alt=\"\" class=\"wp-image-12214\" srcset=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj4.png 1222w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj4-300x76.png 300w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj4-1024x258.png 1024w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj4-768x194.png 768w\" sizes=\"auto, (max-width: 1222px) 100vw, 1222px\" \/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj5.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1217\" height=\"535\" data-id=\"12215\" src=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj5.png\" alt=\"\" class=\"wp-image-12215\" srcset=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj5.png 1217w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj5-300x132.png 300w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj5-1024x450.png 1024w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj5-768x338.png 768w\" sizes=\"auto, (max-width: 1217px) 100vw, 1217px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Now we add a graph with this item (I hope you know how to create graphs in Zabbix) and it&#8217;s time to test. I will generate thousands of OPTIONS requests to my OpenSIPS with the <a rel=\"noreferrer noopener\" href=\"http:\/\/sipp.sourceforge.net\/\" data-type=\"URL\" data-id=\"http:\/\/sipp.sourceforge.net\/\" target=\"_blank\">sipp<\/a> tool (I also recommend this <a href=\"https:\/\/tomeko.net\/other\/sipp\/sipp_cheatsheet.php?lang=en\" data-type=\"URL\" data-id=\"https:\/\/tomeko.net\/other\/sipp\/sipp_cheatsheet.php?lang=en\" target=\"_blank\" rel=\"noreferrer noopener\">sipp cheatsheet<\/a>).<\/p>\n\n\n\n<p>Download <a rel=\"noreferrer noopener\" href=\"https:\/\/tomeko.net\/other\/sipp\/scenarios\/OPTIONS.xml\" data-type=\"URL\" data-id=\"https:\/\/tomeko.net\/other\/sipp\/scenarios\/OPTIONS.xml\" target=\"_blank\">OPTIONS.xml<\/a> scenario file, and generate 10000 OPTIONS requests with call rate of 10 (I assume that your OpenSIPS, like mine, answers &#8220;200 OK&#8221;):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-vivid-red-color has-text-color\">sipp 192.168.88.244 -sf OPTIONS.xml -l 10000 -m 10000 -r 10<\/pre>\n\n\n\n<p>Finally, here is the graph showing your OpenSIPS SL module 2xx processed replies statistics:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj6.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"217\" src=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj6-1024x217.png\" alt=\"\" class=\"wp-image-12216\" srcset=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj6-1024x217.png 1024w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj6-300x64.png 300w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj6-768x163.png 768w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj6-1536x326.png 1536w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2022\/03\/ozj6.png 1736w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>This is how you can monitor OpenSIPS with Zabbix using JSON.<\/p>\n\n\n\n<p>Have fun!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide will help you to understand how OpenSIPS can be monitored with Zabbix, sharing its statistic data via HTTP interface in JSON format. This article assumes using OpenSIPS 3.2 and Zabbix 6. Enable embedded HTTP server&nbsp;and HTTP support for Management Interface in your OpenSIPS: loadmodule &#8220;httpd.so&#8221; modparam(&#8220;httpd&#8221;, &#8220;ip&#8221;, &#8220;192.168.88.244&#8221;) modparam(&#8220;httpd&#8221;, &#8220;port&#8221;, 8888) # :8888\/mi [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[277,278,279,208,237],"class_list":["post-12204","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-http-agent","tag-json","tag-jsonpath","tag-opensips","tag-zabbix"],"_links":{"self":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts\/12204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12204"}],"version-history":[{"count":35,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts\/12204\/revisions"}],"predecessor-version":[{"id":12247,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts\/12204\/revisions\/12247"}],"wp:attachment":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}