{"id":154,"date":"2017-09-15T16:49:16","date_gmt":"2017-09-15T19:49:16","guid":{"rendered":"http:\/\/docs.unitplatform.io\/?p=154"},"modified":"2017-11-23T14:12:04","modified_gmt":"2017-11-23T16:12:04","slug":"developing-plugins-to-collect-snmp-data","status":"publish","type":"post","link":"https:\/\/docs.unitplatform.io\/en\/developing-plugins-to-collect-snmp-data\/","title":{"rendered":"Developing plugins to collect SNMP data","raw":"Developing plugins to collect SNMP data"},"content":{"rendered":"<blockquote><p>This is the third post about custom plugins. We recommend you to take a look at our previous posts about plugin <a href=\"http:\/\/docs.unitplatform.io\/en\/developing-custom-plugins\/\" target=\"_blank\" rel=\"noopener\">development<\/a> and <a href=\"http:\/\/docs.unitplatform.io\/en\/using-custom-plugins\/\" target=\"_blank\" rel=\"noopener\">usage<\/a>.<\/p><\/blockquote>\n<p>The SNMP protocol is one of the most used methods to obtain monitoring information from various types of devices, such as servers, switches, routers, printers and temperature sensors. In this post, we&#8217;ll detail how to create a plugin that will connect to an SNMP device using credentials.<\/p>\n<h2>Creating a credential<\/h2>\n<p>The Unit Platform, by default, comes with an SNMP v2c credential with the &#8220;public&#8221; community. In case the community you are using in your environment is a different one, you must create a new credential. For that, you need to access the configuration menu and click on\u00a0<strong>Credentials<\/strong>:<\/p>\n<div id=\"attachment_155\" style=\"width: 406px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/credentials_menu.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-155\" class=\"wp-image-155 size-full\" src=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/credentials_menu.png\" alt=\"\" width=\"396\" height=\"436\" \/><\/a><p id=\"caption-attachment-155\" class=\"wp-caption-text\">Credentials menu<\/p><\/div>\n<p>Click on &#8220;Add credential&#8221;. If the Unit Platform installation is in a multitenancy environment, select the company that will use the credential, then select the type of SNMP credential you&#8217;ll use. Unit Platform supports three types of SNMP credentials: <strong>SNMPv1<\/strong>, <strong>SNMPv2c<\/strong> e <strong>SNMPv3<\/strong>.<\/p>\n<p>For every credential type, a different set of information will be required. In this simple example, we&#8217;ll use SNMPv2c. Create a credential following the example below:<\/p>\n<div id=\"attachment_159\" style=\"width: 1083px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/credentials_add.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-159\" class=\"wp-image-159 size-full\" src=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/credentials_add.png\" alt=\"\" width=\"1073\" height=\"365\" \/><\/a><p id=\"caption-attachment-159\" class=\"wp-caption-text\">Adding a credential<\/p><\/div>\n<h2>Using SNMP credentials<\/h2>\n<p>To use a credential, we must create a plugin that&#8217;s able to receive a string argument. This string will contain all the credential&#8217;s variables separated by &#8220;;&#8221;. Every SNMP credential type is listed below, along with the credential&#8217;s formats:<\/p>\n<ul>\n<li>SNMP v1: <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">snmpv1;[community]<\/code><\/li>\n<li>SNMP v2c: <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">snmpv2c;[community]<\/code><\/li>\n<li>SNMP v3: <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">snmpv3;[username];[security level];[authentication method];[authentication password];[cryptography method];[cryptography password]<\/code>\n<ul>\n<li>security level: <em>authpriv<\/em>, <em>authnopriv<\/em> or\u00a0<em>noauthnopriv<\/em><\/li>\n<li>authentication method: <em>sha<\/em> or\u00a0<em>md5<\/em><\/li>\n<li>cryptography method: <em>3desede, aes128, aes192, aes256, des<\/em> or\u00a0<em>idea<\/em><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Programming the plugin<\/h2>\n<p>Below is an example of a plugin that checks device uptime through SNMP. It&#8217;s a prerequisite that the monitored device has the SNMP service running and that the Unit Platform server has access to the same device&#8217;s 161 \/ UDP port.<\/p>\n<p>The plugin&#8217;s written in Bash and will run locally on the Unit Platform. This plugin works for all SNMP versions and is named <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">my_first_plugin_snmp.sh<\/code>.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#!\/bin\/bash\r\n\r\naddress=$1\r\ncredential=$2\r\n\r\nsnmpVersion=$(echo $credential | cut -d \";\" -f 1)\r\n\r\nif [ \"$snmpVersion\" == \"snmpv1\" ]; then\r\n    snmpCommunity=$(echo \"$credential\" | cut -d \";\" -f2)\r\n    snmpArgs=\"-v1 -c $snmpCommunity\"\r\nfi\r\n\r\nif [ \"$snmpVersion\" == \"snmpv2c\" ]; then\r\n    snmpCommunity=$(echo \"$credential\" | cut -d \";\" -f2)\r\n    snmpArgs=\"-v2c -c $snmpCommunity\"\r\nfi\r\n\r\nif [ \"$snmpVersion\" == \"snmpv3\" ]; then\r\n    snmpUser=$(echo \"$credential\" | cut -d \";\" -f2)\r\n    snmpLevel=$(echo \"$credential\" | cut -d \";\" -f3)\r\n    snmpTypeAuth=$(echo \"$credential\" | cut -d \";\" -f4)\r\n    snmpPassAuth=$(echo \"$credential\" | cut -d \";\" -f5)\r\n    snmpTypeCrypt=$(echo \"$credential\" | cut -d \";\" -f6)\r\n    snmpPassCrypt=$(echo \"$credential\" | cut -d \";\" -f7)\r\n\r\n    [ \"$snmpLevel\" == \"noauthnopriv\" ] &amp;&amp; snmpArgs=\"-v3 -u $snmpUser -l $snmpLevel\"\r\n    [ \"$snmpLevel\" == \"authnopriv\" ] &amp;&amp;   snmpArgs=\"-v3 -u $snmpUser -l $snmpLevel -a $snmpTypeAuth -A $snmpPassAuth\"\r\n    [ \"$snmpLevel\" == \"authpriv\" ] &amp;&amp;     snmpArgs=\"-v3 -u $snmpUser -l $snmpLevel -a $snmpTypeAuth -A $snmpPassAuth -x $snmpTypeCrypt -X $snmpPassCrypt\"\r\nfi\r\n\r\nresult=$(snmpget -OevQ $address $snmpArgs sysUpTimeInstance)\r\n\r\necho $result\r\n<\/pre>\n<p>This plugin has two entry arguments: <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">address<\/code> and <code class=\"EnlighterJSRAW\" data-enlighter-linenumbers=\"false\">credential<\/code>. These parameters must be specified in the plugin&#8217;s command line during the plugin&#8217;s upload.<\/p>\n<p>More details about plugin development can be seen here in <a href=\"http:\/\/docs.unitplatform.io\/en\/developing-custom-plugins\/\" target=\"_blank\" rel=\"noopener\">this post<\/a>.<\/p>\n<h2>Uploading the plugin<\/h2>\n<p>To register this code as a plugin, the steps to be followed are almost the same as described <a href=\"http:\/\/docs.unitplatform.io\/en\/using-custom-plugins\/\" target=\"_blank\" rel=\"noopener\">here<\/a>, the only different thing&#8217;s that we&#8217;ll select SNMPv2c as the credential type:<\/p>\n<p><a href=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/plugin_snmp_add-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-171 size-full\" src=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/plugin_snmp_add-1.png\" alt=\"\" width=\"1079\" height=\"800\" \/><\/a><\/p>\n<p><strong>Item 1 &#8211; Company:<\/strong> select the company that will make use of the plugin.<\/p>\n<p><strong>Item 2 &#8211; Plugin name:<\/strong> choose a name for the plugin.<\/p>\n<p><strong>Item 3 &#8211; Credential type:<\/strong> select the credential type the plugin supports. In this example, we&#8217;ll use SNMPv2c.<\/p>\n<p><strong>Item 4 &#8211; Send Script:<\/strong> upload the file &#8220;my_first_plugin_snmp.sh&#8221;.<\/p>\n<p><strong>Item 5 &#8211; Command line arguments:<\/strong> The variable &#8220;address&#8221; must be used because when the monitored item is executed, the plugin will connect to the desired machine. In addition to this variable, we&#8217;ll also use the &#8220;credential&#8221;, which will be the string with all the necessary variables separated by &#8220;;&#8221;.<\/p>\n<p>Click on &#8220;Test plugin&#8221;.<\/p>\n<div id=\"attachment_169\" style=\"width: 1172px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/plugin_snmp_test.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-169\" class=\"wp-image-169 size-full\" src=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/plugin_snmp_test.png\" alt=\"\" width=\"1162\" height=\"445\" \/><\/a><p id=\"caption-attachment-169\" class=\"wp-caption-text\">Plugin test<\/p><\/div>\n<p>On the test execution interface, all credentials of the type chosen in the previous screen will be displayed. Select the credential that was created before, as well as a device to point the test to. Click on &#8220;Execute test&#8221;.<\/p>\n<p>By successfully completing the test, proceed to the next steps of the plugin creation wizard to specify the plugin output and monitoring rules. For more details about plugin usage, we recommend reading <a href=\"http:\/\/docs.unitplatform.io\/en\/using-custom-plugins\/\" target=\"_blank\" rel=\"noopener\">this post<\/a>.<\/p>\n","protected":false,"raw":"<blockquote>This is the third post about custom plugins. We recommend you to take a look at our previous posts about plugin <a href=\"http:\/\/docs.unitplatform.io\/en\/developing-custom-plugins\/\" target=\"_blank\" rel=\"noopener\">development<\/a> and <a href=\"http:\/\/docs.unitplatform.io\/en\/using-custom-plugins\/\" target=\"_blank\" rel=\"noopener\">usage<\/a>.<\/blockquote>\r\nThe SNMP protocol is one of the most used methods to obtain monitoring information from various types of devices, such as servers, switches, routers, printers and temperature sensors. In this post, we'll detail how to create a plugin that will connect to an SNMP device using credentials.\r\n<h2>Creating a credential<\/h2>\r\nThe Unit Platform, by default, comes with an SNMP v2c credential with the \"public\" community. In case the community you are using in your environment is a different one, you must create a new credential. For that, you need to access the configuration menu and click on\u00a0<strong>Credentials<\/strong>:\r\n\r\n[caption id=\"attachment_155\" align=\"alignnone\" width=\"396\"]<a href=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/credentials_menu.png\"><img class=\"wp-image-155 size-full\" src=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/credentials_menu.png\" alt=\"\" width=\"396\" height=\"436\" \/><\/a> Credentials menu[\/caption]\r\n\r\nClick on \"Add credential\". If the Unit Platform installation is in a multitenancy environment, select the company that will use the credential, then select the type of SNMP credential you'll use. Unit Platform supports three types of SNMP credentials: <strong>SNMPv1<\/strong>, <strong>SNMPv2c<\/strong> e <strong>SNMPv3<\/strong>.\r\n\r\nFor every credential type, a different set of information will be required. In this simple example, we'll use SNMPv2c. Create a credential following the example below:\r\n\r\n[caption id=\"attachment_159\" align=\"alignnone\" width=\"1073\"]<a href=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/credentials_add.png\"><img class=\"wp-image-159 size-full\" src=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/credentials_add.png\" alt=\"\" width=\"1073\" height=\"365\" \/><\/a> Adding a credential[\/caption]\r\n<h2>Using SNMP credentials<\/h2>\r\nTo use a credential, we must create a plugin that's able to receive a string argument. This string will contain all the credential's variables separated by \";\". Every SNMP credential type is listed below, along with the credential's formats:\r\n<ul>\r\n \t<li>SNMP v1: <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">snmpv1;[community]<\/code><\/li>\r\n \t<li>SNMP v2c: <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">snmpv2c;[community]<\/code><\/li>\r\n \t<li>SNMP v3: <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">snmpv3;[username];[security level];[authentication method];[authentication password];[cryptography method];[cryptography password]<\/code>\r\n<ul>\r\n \t<li>security level: <em>authpriv<\/em>, <em>authnopriv<\/em> or\u00a0<em>noauthnopriv<\/em><\/li>\r\n \t<li>authentication method: <em>sha<\/em> or\u00a0<em>md5<\/em><\/li>\r\n \t<li>cryptography method: <em>3desede, aes128, aes192, aes256, des<\/em> or\u00a0<em>idea<\/em><\/li>\r\n<\/ul>\r\n<\/li>\r\n<\/ul>\r\n<h2>Programming the plugin<\/h2>\r\nBelow is an example of a plugin that checks device uptime through SNMP. It's a prerequisite that the monitored device has the SNMP service running and that the Unit Platform server has access to the same device's 161 \/ UDP port.\r\n\r\nThe plugin's written in Bash and will run locally on the Unit Platform. This plugin works for all SNMP versions and is named <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">my_first_plugin_snmp.sh<\/code>.\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#!\/bin\/bash\r\n\r\naddress=$1\r\ncredential=$2\r\n\r\nsnmpVersion=$(echo $credential | cut -d \";\" -f 1)\r\n\r\nif [ \"$snmpVersion\" == \"snmpv1\" ]; then\r\n    snmpCommunity=$(echo \"$credential\" | cut -d \";\" -f2)\r\n    snmpArgs=\"-v1 -c $snmpCommunity\"\r\nfi\r\n\r\nif [ \"$snmpVersion\" == \"snmpv2c\" ]; then\r\n    snmpCommunity=$(echo \"$credential\" | cut -d \";\" -f2)\r\n    snmpArgs=\"-v2c -c $snmpCommunity\"\r\nfi\r\n\r\nif [ \"$snmpVersion\" == \"snmpv3\" ]; then\r\n    snmpUser=$(echo \"$credential\" | cut -d \";\" -f2)\r\n    snmpLevel=$(echo \"$credential\" | cut -d \";\" -f3)\r\n    snmpTypeAuth=$(echo \"$credential\" | cut -d \";\" -f4)\r\n    snmpPassAuth=$(echo \"$credential\" | cut -d \";\" -f5)\r\n    snmpTypeCrypt=$(echo \"$credential\" | cut -d \";\" -f6)\r\n    snmpPassCrypt=$(echo \"$credential\" | cut -d \";\" -f7)\r\n\r\n    [ \"$snmpLevel\" == \"noauthnopriv\" ] &amp;&amp; snmpArgs=\"-v3 -u $snmpUser -l $snmpLevel\"\r\n    [ \"$snmpLevel\" == \"authnopriv\" ] &amp;&amp;   snmpArgs=\"-v3 -u $snmpUser -l $snmpLevel -a $snmpTypeAuth -A $snmpPassAuth\"\r\n    [ \"$snmpLevel\" == \"authpriv\" ] &amp;&amp;     snmpArgs=\"-v3 -u $snmpUser -l $snmpLevel -a $snmpTypeAuth -A $snmpPassAuth -x $snmpTypeCrypt -X $snmpPassCrypt\"\r\nfi\r\n\r\nresult=$(snmpget -OevQ $address $snmpArgs sysUpTimeInstance)\r\n\r\necho $result\r\n<\/pre>\r\nThis plugin has two entry arguments: <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">address<\/code> and <code class=\"EnlighterJSRAW\" data-enlighter-linenumbers=\"false\">credential<\/code>. These parameters must be specified in the plugin's command line during the plugin's upload.\r\n\r\nMore details about plugin development can be seen here in <a href=\"http:\/\/docs.unitplatform.io\/en\/developing-custom-plugins\/\" target=\"_blank\" rel=\"noopener\">this post<\/a>.\r\n<h2>Uploading the plugin<\/h2>\r\nTo register this code as a plugin, the steps to be followed are almost the same as described <a href=\"http:\/\/docs.unitplatform.io\/en\/using-custom-plugins\/\" target=\"_blank\" rel=\"noopener\">here<\/a>, the only different thing's that we'll select SNMPv2c as the credential type:\r\n\r\n<a href=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/plugin_snmp_add-1.png\"><img class=\"alignnone wp-image-171 size-full\" src=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/plugin_snmp_add-1.png\" alt=\"\" width=\"1079\" height=\"800\" \/><\/a>\r\n\r\n<strong>Item 1 - Company:<\/strong> select the company that will make use of the plugin.\r\n\r\n<strong>Item 2 - Plugin name:<\/strong> choose a name for the plugin.\r\n\r\n<strong>Item 3 - Credential type:<\/strong> select the credential type the plugin supports. In this example, we'll use SNMPv2c.\r\n\r\n<strong>Item 4 - Send Script:<\/strong> upload the file \"my_first_plugin_snmp.sh\".\r\n\r\n<strong>Item 5 - Command line arguments:<\/strong> The variable \"address\" must be used because when the monitored item is executed, the plugin will connect to the desired machine. In addition to this variable, we'll also use the \"credential\", which will be the string with all the necessary variables separated by \";\".\r\n\r\nClick on \"Test plugin\".\r\n\r\n[caption id=\"attachment_169\" align=\"alignnone\" width=\"1162\"]<a href=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/plugin_snmp_test.png\"><img class=\"wp-image-169 size-full\" src=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/plugin_snmp_test.png\" alt=\"\" width=\"1162\" height=\"445\" \/><\/a> Plugin test[\/caption]\r\n\r\nOn the test execution interface, all credentials of the type chosen in the previous screen will be displayed. Select the credential that was created before, as well as a device to point the test to. Click on \"Execute test\".\r\n\r\nBy successfully completing the test, proceed to the next steps of the plugin creation wizard to specify the plugin output and monitoring rules. For more details about plugin usage, we recommend reading <a href=\"http:\/\/docs.unitplatform.io\/en\/using-custom-plugins\/\" target=\"_blank\" rel=\"noopener\">this post<\/a>."},"excerpt":{"rendered":"<p>Learn how to integrate SNMP plugins with Unit Platform<\/p>\n","protected":false,"raw":"Learn how to integrate SNMP plugins with Unit Platform"},"author":1,"featured_media":178,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_pt_post_content":"<blockquote>Este \u00e9 o terceiro post sobre plugins na Unit Platform. Recomendamos a leitura dos posts anteriores sobre <a href=\"http:\/\/docs.unitplatform.io\/desenvolvendo-plugins-personalizados\/\">desenvolvimento<\/a> e <a href=\"http:\/\/docs.unitplatform.io\/cadastro-de-plugins-personalizados\/\">cadastro<\/a> de plugins.<\/blockquote>\r\nO protocolo SNMP \u00e9 um dos m\u00e9todos mais usados para obter informa\u00e7\u00f5es de monitoramento dos mais variados dispositivos, desde servidores, switches, roteadores, at\u00e9 impressoras e sensores de temperatura ambiental. Neste post veremos como criar um plugin que conectar\u00e1 em um dispositivo usando uma credencial SNMP.\r\n<h2>Cria\u00e7\u00e3o de uma credencial<\/h2>\r\nA Unit Platform disponibiliza por padr\u00e3o uma credencial de SNMP v2c pr\u00e9-cadastrada para a comunidade \"public\". Caso a comunidade que esteja em uso no seu ambiente seja diferente, voc\u00ea dever\u00e1 criar um novo cadastro de credencial. Para isso, acesse o menu de configura\u00e7\u00f5es e em seguida acesse <strong>Credenciais<\/strong>:\r\n\r\n[caption id=\"attachment_155\" align=\"alignnone\" width=\"396\"]<a href=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/credentials_menu.png\"><img class=\"wp-image-155 size-full\" src=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/credentials_menu.png\" alt=\"\" width=\"396\" height=\"436\" \/><\/a> Menu Credenciais[\/caption]\r\n\r\nClique em \"Adicionar credencial\". Caso a instala\u00e7\u00e3o da Unit Platform esteja em um ambiente multiempresa, selecione a empresa a qual a credencial pertence. Em seguida selecione o tipo de credencial SNMP que voc\u00ea deseja utilizar. A Unit Platform suporta tr\u00eas tipos de credencial SNMP: <strong>SNMPv1<\/strong>, <strong>SNMPv2c<\/strong> e <strong>SNMPv3<\/strong>.\r\n\r\nConforme cada tipo de credencial, ser\u00e1 solicitado um conjunto diferente de dados. Como o plugin que criaremos nesse tutorial \u00e9 simples, usaremos uma credencial SNMPv2c. Crie uma credencial conforme a imagem abaixo e salve:\r\n\r\n[caption id=\"attachment_159\" align=\"alignnone\" width=\"1073\"]<a href=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/credentials_add.png\"><img class=\"size-full wp-image-159\" src=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/credentials_add.png\" alt=\"\" width=\"1073\" height=\"365\" \/><\/a> Adicionando uma credencial[\/caption]\r\n<h2>Usando credenciais SNMP<\/h2>\r\nPara usar a credencial, deve-se criar um plugin que receba um argumento do tipo string. Essa string conter\u00e1 todas as vari\u00e1veis da credencial separadas por \u201c;\u201d. Abaixo est\u00e1 listado o formato das credenciais SNMP usadas na ferramenta:\r\n<ul>\r\n \t<li>SNMP v1: <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">snmpv1;[community]<\/code><\/li>\r\n \t<li>SNMP v2c: <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">snmpv2c;[community]<\/code><\/li>\r\n \t<li>SNMP v3: <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">snmpv3;[username];[security level];[authentication method];[authentication password];[cryptography method];[cryptography password]<\/code>\r\n<ul>\r\n \t<li>security level: <em>authpriv<\/em>, <em>authnopriv<\/em> ou <em>noauthnopriv<\/em><\/li>\r\n \t<li>authentication method: <em>sha<\/em> ou <em>md5<\/em><\/li>\r\n \t<li>cryptography method: <em>3desede, aes128, aes192, aes256, des<\/em> ou <em>idea<\/em><\/li>\r\n<\/ul>\r\n<\/li>\r\n<\/ul>\r\n<h2>Programando o plugin<\/h2>\r\nAbaixo est\u00e1 um exemplo de plugin que verifica o <em>uptime<\/em> do dispositivo atrav\u00e9s do SNMP. \u00c9 pr\u00e9-requisito que o dispositivo monitorado esteja com o servi\u00e7o de SNMP rodando, e que o servidor Unit Platform tenha acesso \u00e0 porta 161\/UDP do mesmo.\r\n\r\nO plugin est\u00e1 escrito em Bash e ser\u00e1 executado localmente na Unit Platform. Este plugin funciona para todas as vers\u00f5es SNMP e est\u00e1 nomeado como <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">my_first_plugin_snmp.sh<\/code>.\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#!\/bin\/bash\r\n\r\naddress=$1\r\ncredential=$2\r\n\r\nsnmpVersion=$(echo $credential | cut -d \";\" -f 1)\r\n\r\nif [ \"$snmpVersion\" == \"snmpv1\" ]; then\r\n    snmpCommunity=$(echo \"$credential\" | cut -d \";\" -f2)\r\n    snmpArgs=\"-v1 -c $snmpCommunity\"\r\nfi\r\n\r\nif [ \"$snmpVersion\" == \"snmpv2c\" ]; then\r\n    snmpCommunity=$(echo \"$credential\" | cut -d \";\" -f2)\r\n    snmpArgs=\"-v2c -c $snmpCommunity\"\r\nfi\r\n\r\nif [ \"$snmpVersion\" == \"snmpv3\" ]; then\r\n    snmpUser=$(echo \"$credential\" | cut -d \";\" -f2)\r\n    snmpLevel=$(echo \"$credential\" | cut -d \";\" -f3)\r\n    snmpTypeAuth=$(echo \"$credential\" | cut -d \";\" -f4)\r\n    snmpPassAuth=$(echo \"$credential\" | cut -d \";\" -f5)\r\n    snmpTypeCrypt=$(echo \"$credential\" | cut -d \";\" -f6)\r\n    snmpPassCrypt=$(echo \"$credential\" | cut -d \";\" -f7)\r\n\r\n    [ \"$snmpLevel\" == \"noauthnopriv\" ] &amp;&amp; snmpArgs=\"-v3 -u $snmpUser -l $snmpLevel\"\r\n    [ \"$snmpLevel\" == \"authnopriv\" ] &amp;&amp;   snmpArgs=\"-v3 -u $snmpUser -l $snmpLevel -a $snmpTypeAuth -A $snmpPassAuth\"\r\n    [ \"$snmpLevel\" == \"authpriv\" ] &amp;&amp;     snmpArgs=\"-v3 -u $snmpUser -l $snmpLevel -a $snmpTypeAuth -A $snmpPassAuth -x $snmpTypeCrypt -X $snmpPassCrypt\"\r\nfi\r\n\r\nresult=$(snmpget -OevQ $address $snmpArgs sysUpTimeInstance)\r\n\r\necho $result\r\n<\/pre>\r\nEste plugin possui dois par\u00e2metros de entrada, <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">address<\/code> e <code class=\"EnlighterJSRAW\" data-enlighter-linenumbers=\"false\">credential<\/code>. Estes par\u00e2metros dever\u00e3o ser especificados nos argumentos da linha de comando do plugin durante o cadastro.\r\n<blockquote>Mais detalhes sobre desenvolvimento de plugins podem ser vistos <a href=\"http:\/\/docs.unitplatform.io\/desenvolvendo-plugins-personalizados\/\">neste post<\/a>.<\/blockquote>\r\n<h2>Cadastrando o plugin<\/h2>\r\nO processo de carregamento deste plugin \u00e9 praticamente igual ao descrito <a href=\"http:\/\/docs.unitplatform.io\/cadastro-de-plugins-personalizados\/\">neste post<\/a>, com a diferen\u00e7a que no campo de sele\u00e7\u00e3o de credenciais especificaremos que este plugin ir\u00e1 usar uma credencial do tipo SNMPv2c:\r\n\r\n<a href=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/plugin_snmp_add-1.png\"><img class=\"alignnone wp-image-171 size-full\" src=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/plugin_snmp_add-1.png\" alt=\"\" width=\"1079\" height=\"800\" \/><\/a>\r\n\r\n<strong>Item 1 - Empresa:<\/strong> selecione a empresa que far\u00e1 uso do plugin.\r\n\r\n<strong>Item 2 - Nome do plugin:<\/strong> escolha um nome de exibi\u00e7\u00e3o para o plugin.\r\n\r\n<strong>Item 3 - Tipo da Credencial:<\/strong> selecionar o tipo de credencial que o dispositivo aceitar. Neste exemplo \u00e9 utilizado o SNMP vers\u00e3o 2c.\r\n\r\n<strong>Item 4 - Enviar Script: <\/strong>fazer upload do arquivo \u201cmy_first_plugin_snmp.sh\u201d.\r\n\r\n<strong>Item 5 - Argumentos da linha de comando:<\/strong> aqui deve ser utilizada a vari\u00e1vel \u201c$address$\u201d, que se encarregar\u00e1 de passar ao plugin o endere\u00e7o do dispositivo no qual o SNMP deve buscar os dados de uptime.. Al\u00e9m dessa vari\u00e1vel, utilizaremos tamb\u00e9m a vari\u00e1vel \u201c$credential$\u201d, para que o sistema passe ao plugin a credencial que ser\u00e1 usada para autentica\u00e7\u00e3o.\r\n\r\nClicar em \u201cTestar plugin\u201d.\r\n\r\n[caption id=\"attachment_169\" align=\"alignnone\" width=\"1162\"]<a href=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/plugin_snmp_test.png\"><img class=\"size-full wp-image-169\" src=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/plugin_snmp_test.png\" alt=\"\" width=\"1162\" height=\"445\" \/><\/a> Testando o plugin[\/caption]\r\n\r\nNa interface de execu\u00e7\u00e3o do teste, ser\u00e3o exibidas todas as credenciais do tipo escolhido na tela anterior (SNMPv2c). Selecione a credencial criada anteriormente e um dispositivo para executar o teste. Clicar em \u201cExecutar teste\u201d.\r\n\r\nFinalizando com sucesso o teste, prossiga para os pr\u00f3ximos passos do wizard de cria\u00e7\u00e3o de plugins para especificar a sa\u00edda do plugin e as regras de monitoramento. Caso ainda existam d\u00favidas, recomendamos a leitura do post sobre <a href=\"http:\/\/docs.unitplatform.io\/cadastro-de-plugins-personalizados\/\">Cadastramento de plugins na Unit Platform<\/a>.","_pt_post_name":"desenvolvendo-plugins-para-coletar-dados-via-snmp","_pt_post_excerpt":"Aprenda a integrar plugins SNMP com a Unit Platform","_pt_post_title":"Desenvolvendo plugins para coletar dados via SNMP","_en_post_content":"<blockquote>This is the third post about custom plugins. We recommend you to take a look at our previous posts about plugin <a href=\"http:\/\/docs.unitplatform.io\/en\/developing-custom-plugins\/\" target=\"_blank\" rel=\"noopener\">development<\/a> and <a href=\"http:\/\/docs.unitplatform.io\/en\/using-custom-plugins\/\" target=\"_blank\" rel=\"noopener\">usage<\/a>.<\/blockquote>\r\nThe SNMP protocol is one of the most used methods to obtain monitoring information from various types of devices, such as servers, switches, routers, printers and temperature sensors. In this post, we'll detail how to create a plugin that will connect to an SNMP device using credentials.\r\n<h2>Creating a credential<\/h2>\r\nThe Unit Platform, by default, comes with an SNMP v2c credential with the \"public\" community. In case the community you are using in your environment is a different one, you must create a new credential. For that, you need to access the configuration menu and click on\u00a0<strong>Credentials<\/strong>:\r\n\r\n[caption id=\"attachment_155\" align=\"alignnone\" width=\"396\"]<a href=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/credentials_menu.png\"><img class=\"wp-image-155 size-full\" src=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/credentials_menu.png\" alt=\"\" width=\"396\" height=\"436\" \/><\/a> Credentials menu[\/caption]\r\n\r\nClick on \"Add credential\". If the Unit Platform installation is in a multitenancy environment, select the company that will use the credential, then select the type of SNMP credential you'll use. Unit Platform supports three types of SNMP credentials: <strong>SNMPv1<\/strong>, <strong>SNMPv2c<\/strong> e <strong>SNMPv3<\/strong>.\r\n\r\nFor every credential type, a different set of information will be required. In this simple example, we'll use SNMPv2c. Create a credential following the example below:\r\n\r\n[caption id=\"attachment_159\" align=\"alignnone\" width=\"1073\"]<a href=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/credentials_add.png\"><img class=\"wp-image-159 size-full\" src=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/credentials_add.png\" alt=\"\" width=\"1073\" height=\"365\" \/><\/a> Adding a credential[\/caption]\r\n<h2>Using SNMP credentials<\/h2>\r\nTo use a credential, we must create a plugin that's able to receive a string argument. This string will contain all the credential's variables separated by \";\". Every SNMP credential type is listed below, along with the credential's formats:\r\n<ul>\r\n \t<li>SNMP v1: <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">snmpv1;[community]<\/code><\/li>\r\n \t<li>SNMP v2c: <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">snmpv2c;[community]<\/code><\/li>\r\n \t<li>SNMP v3: <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">snmpv3;[username];[security level];[authentication method];[authentication password];[cryptography method];[cryptography password]<\/code>\r\n<ul>\r\n \t<li>security level: <em>authpriv<\/em>, <em>authnopriv<\/em> or\u00a0<em>noauthnopriv<\/em><\/li>\r\n \t<li>authentication method: <em>sha<\/em> or\u00a0<em>md5<\/em><\/li>\r\n \t<li>cryptography method: <em>3desede, aes128, aes192, aes256, des<\/em> or\u00a0<em>idea<\/em><\/li>\r\n<\/ul>\r\n<\/li>\r\n<\/ul>\r\n<h2>Programming the plugin<\/h2>\r\nBelow is an example of a plugin that checks device uptime through SNMP. It's a prerequisite that the monitored device has the SNMP service running and that the Unit Platform server has access to the same device's 161 \/ UDP port.\r\n\r\nThe plugin's written in Bash and will run locally on the Unit Platform. This plugin works for all SNMP versions and is named <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">my_first_plugin_snmp.sh<\/code>.\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#!\/bin\/bash\r\n\r\naddress=$1\r\ncredential=$2\r\n\r\nsnmpVersion=$(echo $credential | cut -d \";\" -f 1)\r\n\r\nif [ \"$snmpVersion\" == \"snmpv1\" ]; then\r\n    snmpCommunity=$(echo \"$credential\" | cut -d \";\" -f2)\r\n    snmpArgs=\"-v1 -c $snmpCommunity\"\r\nfi\r\n\r\nif [ \"$snmpVersion\" == \"snmpv2c\" ]; then\r\n    snmpCommunity=$(echo \"$credential\" | cut -d \";\" -f2)\r\n    snmpArgs=\"-v2c -c $snmpCommunity\"\r\nfi\r\n\r\nif [ \"$snmpVersion\" == \"snmpv3\" ]; then\r\n    snmpUser=$(echo \"$credential\" | cut -d \";\" -f2)\r\n    snmpLevel=$(echo \"$credential\" | cut -d \";\" -f3)\r\n    snmpTypeAuth=$(echo \"$credential\" | cut -d \";\" -f4)\r\n    snmpPassAuth=$(echo \"$credential\" | cut -d \";\" -f5)\r\n    snmpTypeCrypt=$(echo \"$credential\" | cut -d \";\" -f6)\r\n    snmpPassCrypt=$(echo \"$credential\" | cut -d \";\" -f7)\r\n\r\n    [ \"$snmpLevel\" == \"noauthnopriv\" ] &amp;&amp; snmpArgs=\"-v3 -u $snmpUser -l $snmpLevel\"\r\n    [ \"$snmpLevel\" == \"authnopriv\" ] &amp;&amp;   snmpArgs=\"-v3 -u $snmpUser -l $snmpLevel -a $snmpTypeAuth -A $snmpPassAuth\"\r\n    [ \"$snmpLevel\" == \"authpriv\" ] &amp;&amp;     snmpArgs=\"-v3 -u $snmpUser -l $snmpLevel -a $snmpTypeAuth -A $snmpPassAuth -x $snmpTypeCrypt -X $snmpPassCrypt\"\r\nfi\r\n\r\nresult=$(snmpget -OevQ $address $snmpArgs sysUpTimeInstance)\r\n\r\necho $result\r\n<\/pre>\r\nThis plugin has two entry arguments: <code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">address<\/code> and <code class=\"EnlighterJSRAW\" data-enlighter-linenumbers=\"false\">credential<\/code>. These parameters must be specified in the plugin's command line during the plugin's upload.\r\n\r\nMore details about plugin development can be seen here in <a href=\"http:\/\/docs.unitplatform.io\/en\/developing-custom-plugins\/\" target=\"_blank\" rel=\"noopener\">this post<\/a>.\r\n<h2>Uploading the plugin<\/h2>\r\nTo register this code as a plugin, the steps to be followed are almost the same as described <a href=\"http:\/\/docs.unitplatform.io\/en\/using-custom-plugins\/\" target=\"_blank\" rel=\"noopener\">here<\/a>, the only different thing's that we'll select SNMPv2c as the credential type:\r\n\r\n<a href=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/plugin_snmp_add-1.png\"><img class=\"alignnone wp-image-171 size-full\" src=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/plugin_snmp_add-1.png\" alt=\"\" width=\"1079\" height=\"800\" \/><\/a>\r\n\r\n<strong>Item 1 - Company:<\/strong> select the company that will make use of the plugin.\r\n\r\n<strong>Item 2 - Plugin name:<\/strong> choose a name for the plugin.\r\n\r\n<strong>Item 3 - Credential type:<\/strong> select the credential type the plugin supports. In this example, we'll use SNMPv2c.\r\n\r\n<strong>Item 4 - Send Script:<\/strong> upload the file \"my_first_plugin_snmp.sh\".\r\n\r\n<strong>Item 5 - Command line arguments:<\/strong> The variable \"address\" must be used because when the monitored item is executed, the plugin will connect to the desired machine. In addition to this variable, we'll also use the \"credential\", which will be the string with all the necessary variables separated by \";\".\r\n\r\nClick on \"Test plugin\".\r\n\r\n[caption id=\"attachment_169\" align=\"alignnone\" width=\"1162\"]<a href=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/plugin_snmp_test.png\"><img class=\"wp-image-169 size-full\" src=\"http:\/\/docs.unitplatform.io\/wp-content\/uploads\/2017\/09\/plugin_snmp_test.png\" alt=\"\" width=\"1162\" height=\"445\" \/><\/a> Plugin test[\/caption]\r\n\r\nOn the test execution interface, all credentials of the type chosen in the previous screen will be displayed. Select the credential that was created before, as well as a device to point the test to. Click on \"Execute test\".\r\n\r\nBy successfully completing the test, proceed to the next steps of the plugin creation wizard to specify the plugin output and monitoring rules. For more details about plugin usage, we recommend reading <a href=\"http:\/\/docs.unitplatform.io\/en\/using-custom-plugins\/\" target=\"_blank\" rel=\"noopener\">this post<\/a>.","_en_post_name":"developing-plugins-to-collect-snmp-data","_en_post_excerpt":"Learn how to integrate SNMP plugins with Unit Platform","_en_post_title":"Developing plugins to collect SNMP data","edit_language":"en","footnotes":""},"categories":[1,6,7,4,8],"tags":[],"class_list":["post-154","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-monitoring","category-plugins","category-snmp","category-tutorials","category-unit-platform-on-premises"],"_links":{"self":[{"href":"https:\/\/docs.unitplatform.io\/en\/wp-json\/wp\/v2\/posts\/154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/docs.unitplatform.io\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.unitplatform.io\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.unitplatform.io\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.unitplatform.io\/en\/wp-json\/wp\/v2\/comments?post=154"}],"version-history":[{"count":22,"href":"https:\/\/docs.unitplatform.io\/en\/wp-json\/wp\/v2\/posts\/154\/revisions"}],"predecessor-version":[{"id":267,"href":"https:\/\/docs.unitplatform.io\/en\/wp-json\/wp\/v2\/posts\/154\/revisions\/267"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.unitplatform.io\/en\/wp-json\/wp\/v2\/media\/178"}],"wp:attachment":[{"href":"https:\/\/docs.unitplatform.io\/en\/wp-json\/wp\/v2\/media?parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.unitplatform.io\/en\/wp-json\/wp\/v2\/categories?post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.unitplatform.io\/en\/wp-json\/wp\/v2\/tags?post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}