{"id":256,"date":"2018-12-06T20:54:00","date_gmt":"2018-12-06T20:54:00","guid":{"rendered":"http:\/\/hanasavi.ir\/?p=256"},"modified":"2018-12-08T15:41:17","modified_gmt":"2018-12-08T15:41:17","slug":"write-a-script-and-add-as-media-type-in-zabbix","status":"publish","type":"post","link":"https:\/\/hanasavi.ir\/index.php\/2018\/12\/06\/write-a-script-and-add-as-media-type-in-zabbix\/","title":{"rendered":"Write a Script and add as media type in zabbix"},"content":{"rendered":"<p>Hi, every body<\/p>\n<p>Today I&#8217;d like to write a article about wrtting a <strong>script<\/strong> by python and use it in <strong>zabbix<\/strong> as a <strong>media type<\/strong> for sending triggers by <strong>sms<\/strong>:<\/p>\n<p>First : create a file with name : ghasedak.py , and write your script.<\/p>\n<p>Pay attention to first line <strong>&#8220;#!\/usr\/bin\/env python&#8221;<\/strong>, this line have to be here for running script by python.<\/p>\n<p>We must use\u00a0<strong>sys.argv .\u00a0<\/strong>sys.argv is a list in Python, which contains the command-line arguments passed to the script.<\/p>\n<p>you can write any script that work&#8217;s with your provider<\/p>\n<pre class=\"lang:default decode:true\">#!\/usr\/bin\/env python\r\nimport requests as requests\r\nimport sys\r\nurl = \"http:\/\/api.smsapp.ir\/v2\/sms\/send\/simple\"\r\n\r\nfrm = 'my number'\r\nto = str(sys.argv[1])\r\nmessage = str(sys.argv[2])\r\n\r\npayload = \"message=\" + message + \"&amp;sender=\" + frm + \"&amp;Receptor=\" + to + \"\"\r\n\r\nheaders = {'content-type': \"application\/x-www-form-urlencoded\",\r\n           'apikey': \"mykey\",\r\n           }\r\nresponse = requests.request(\"POST\", url, data=payload, headers=headers)\r\nprint(response.text)\r\n<\/pre>\n<p>Save this Script and in terminal enter : <strong>sudo chmod +x ghasedak.py<\/strong><\/p>\n<p>GO to Adminisrations-&gt;Media Types and create a new media type, do like this:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-260\" src=\"http:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-00-45-14.png\" alt=\"\" width=\"765\" height=\"417\" srcset=\"https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-00-45-14.png 765w, https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-00-45-14-300x164.png 300w, https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-00-45-14-400x218.png 400w\" sizes=\"(max-width: 765px) 100vw, 765px\" \/><\/p>\n<p>Go to Users and create a new User:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-261\" src=\"http:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-00-48-06.png\" alt=\"\" width=\"734\" height=\"621\" srcset=\"https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-00-48-06.png 734w, https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-00-48-06-300x254.png 300w, https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-00-48-06-355x300.png 355w\" sizes=\"(max-width: 734px) 100vw, 734px\" \/><\/p>\n<p>Then Go to media tab for your user, add media ,select media type and tel_number in &#8216;Send to&#8217;<\/p>\n<p>finally check severity that you want and enable it.<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-262\" src=\"http:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-00-50-30.png\" alt=\"\" width=\"959\" height=\"540\" srcset=\"https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-00-50-30.png 959w, https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-00-50-30-300x169.png 300w, https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-00-50-30-768x432.png 768w, https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-00-50-30-400x225.png 400w\" sizes=\"(max-width: 959px) 100vw, 959px\" \/><\/p>\n<p>Now, Go to configuration-&gt;Actions and create action for <strong>triggers<\/strong>\u00a0:<\/p>\n<p>set conditions ,I use sms if trigger severity is equals <strong>High<\/strong>, change it to your own opnion.<\/p>\n<p>In action you are calling a\u00a0 group of trigger and you can filter in user that each user recieve a specific trigger.<\/p>\n<p>for example admin can recive all trigger severiry and guest can see warning and &#8230;.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-263\" src=\"http:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-00-55-41.png\" alt=\"\" width=\"821\" height=\"481\" srcset=\"https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-00-55-41.png 821w, https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-00-55-41-300x176.png 300w, https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-00-55-41-768x450.png 768w, https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-00-55-41-400x234.png 400w\" sizes=\"(max-width: 821px) 100vw, 821px\" \/><\/p>\n<p>Go to operations tab ,do this<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-264\" src=\"http:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-01-00-11.png\" alt=\"\" width=\"772\" height=\"451\" srcset=\"https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-01-00-11.png 772w, https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-01-00-11-300x175.png 300w, https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-01-00-11-768x449.png 768w, https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-01-00-11-400x234.png 400w\" sizes=\"(max-width: 772px) 100vw, 772px\" \/><\/p>\n<p>add new in Operatios like this:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-265\" src=\"http:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-01-11-52.png\" alt=\"\" width=\"778\" height=\"639\" srcset=\"https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-01-11-52.png 778w, https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-01-11-52-300x246.png 300w, https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-01-11-52-768x631.png 768w, https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-01-11-52-365x300.png 365w\" sizes=\"(max-width: 778px) 100vw, 778px\" \/><\/p>\n<p>add user or users you want to recieve trigger&#8217;s sms:<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-267\" src=\"http:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-01-16-52.png\" alt=\"\" width=\"664\" height=\"639\" srcset=\"https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-01-16-52.png 664w, https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-01-16-52-300x289.png 300w, https:\/\/hanasavi.ir\/wp-content\/uploads\/2018\/12\/Screenshot-from-2018-12-07-01-16-52-312x300.png 312w\" sizes=\"(max-width: 664px) 100vw, 664px\" \/><\/p>\n<p>Do recovery operations and update operations like above<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, every body Today I&#8217;d like to write a article about wrtting a script by python and use it in zabbix as a media type for sending triggers by sms: First : create a file with name : ghasedak.py , and write your script. Pay attention to first line &#8220;#!\/usr\/bin\/env python&#8221;, this line have to&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[29,30,8],"_links":{"self":[{"href":"https:\/\/hanasavi.ir\/index.php\/wp-json\/wp\/v2\/posts\/256"}],"collection":[{"href":"https:\/\/hanasavi.ir\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hanasavi.ir\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hanasavi.ir\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hanasavi.ir\/index.php\/wp-json\/wp\/v2\/comments?post=256"}],"version-history":[{"count":4,"href":"https:\/\/hanasavi.ir\/index.php\/wp-json\/wp\/v2\/posts\/256\/revisions"}],"predecessor-version":[{"id":269,"href":"https:\/\/hanasavi.ir\/index.php\/wp-json\/wp\/v2\/posts\/256\/revisions\/269"}],"wp:attachment":[{"href":"https:\/\/hanasavi.ir\/index.php\/wp-json\/wp\/v2\/media?parent=256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hanasavi.ir\/index.php\/wp-json\/wp\/v2\/categories?post=256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hanasavi.ir\/index.php\/wp-json\/wp\/v2\/tags?post=256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}