{"id":545,"date":"2016-08-01T23:47:56","date_gmt":"2016-08-02T02:47:56","guid":{"rendered":"http:\/\/wordpress.jpcorp.eti.br\/?p=545"},"modified":"2021-12-26T12:31:16","modified_gmt":"2021-12-26T15:31:16","slug":"zabbix-media-types-email-html-sendhtml-py","status":"publish","type":"post","link":"https:\/\/wordpress.jpcorp.eti.br\/?p=545","title":{"rendered":"Zabbix &#8211; Media Types Email-Html &#8220;sendhtml.py&#8221;"},"content":{"rendered":"<p style=\"text-align: justify;\">E chegou a parte de tipos de m\u00eddia para notifica\u00e7\u00f5es, e-mail no Gmail e Telegram postei aqui as configura\u00e7\u00f5es, por\u00e9m antes de uma requisi\u00e7\u00e3o eu pensei:<\/p>\n<blockquote>\n<p style=\"text-align: justify;\">Pow um e-mail em HTML bonitinho iria ser show e com certeza que ir\u00e3o me solicitar isto!<\/p>\n<\/blockquote>\n<p style=\"text-align: justify;\">Ent\u00e3o l\u00e1 vai o Jhones analisar, visto que com a conta de e-mail adicionada no default Media Types do Zabbix ele n\u00e3o envia em HTML, ent\u00e3o necess\u00e1rio uma outra forma, vi alguns posts falando do SendEmail no Zabbix por\u00e9m comigo n\u00e3o funcionou nem por reza, ele dava na a\u00e7\u00e3o como enviado por\u00e9m n\u00e3o enviava nada, ou seja, me \"trollou\" kkkk, depois de apanhar um pouco do SendEmail e nenhum sucesso veio na mente Python, opaaa esse acho que vai rolar, e vamos n\u00f3s criar um script em Python para envio de e-mail em HTML bonitinho para colocar no Zabbix.<\/p>\n<h3 style=\"text-align: justify;\">1 - Script<\/h3>\n<p style=\"text-align: justify;\">O script \u00e9 simples e funcional, primeiramente altere as vari\u00e1veis \"FROM\", \"SRVSMTP\" e \"PASS\", e chamar informando $1=email_destino $2=assunto e $3=mensagem. O Script se encontra dispon\u00edvel no <a href=\"https:\/\/github.com\/jhonespetter\/zabbix-sendhtml\">GITHUB<\/a>.<\/p>\n<pre class=\"lang:python decode:true\">#!\/usr\/bin\/env python\r\n\"\"\"\r\nAutor: Jhones Petter\r\nVersao: 1.0\r\nDescricao: Envio email em html.\r\nPacotes base: libesmtp-devel, libesmtp\r\n\"\"\"\r\n\r\nimport mimetypes, os, smtplib, sys\r\nfrom email import encoders\r\nfrom email.mime.audio import MIMEAudio\r\nfrom email.mime.base import MIMEBase\r\nfrom email.mime.image import MIMEImage\r\nfrom email.mime.multipart import MIMEMultipart\r\nfrom email.mime.text import MIMEText\r\n\r\nFROM='noc@email.com.br'\r\nSRVSMTP='smtp.email.com.br'\r\nPASS='senha'\r\n\r\nDESTINATION=sys.argv[1]\r\nSUBJECT=sys.argv[2]\r\nMESSAGE=sys.argv[3]\r\n\r\nmsg = MIMEMultipart()\r\nmsg['From'] = FROM\r\nmsg['Subject'] = SUBJECT\r\n\r\nmsg.attach(MIMEText(MESSAGE, 'html', 'utf-8'))\r\nraw = msg.as_string()\r\n\r\nsmtp = smtplib.SMTP(SRVSMTP, 587)\r\nsmtp.login(FROM, PASS)\r\nsmtp.sendmail(FROM, DESTINATION, raw)\r\nsmtp.quit()<\/pre>\n<pre class=\"lang:sh decode:true \">.\/sendhtml.py destino@email.com.br 'ASSUNTO' '&lt;h1&gt;MENSAGEM QUE PODE SER EM HTML BONITINHA&lt;\/h1&gt;'<\/pre>\n<h3 style=\"text-align: justify;\">2 - Configura\u00e7\u00e3o Zabbix<\/h3>\n<p style=\"text-align: justify;\">No Zabbix \u00e9 o modelo default, adicione o Script no diret\u00f3rio de AlertScripts, e adicione em \"Administration &gt; Media Types\" conforme imagens abaixo:<\/p>\n<p style=\"text-align: justify;\"><a href=\"http:\/\/wordpress.jpcorp.eti.br\/?attachment_id=548\" rel=\"attachment wp-att-548\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-548\" src=\"http:\/\/wordpress.jpcorp.eti.br\/wp-content\/uploads\/2016\/08\/mediatypes-sendhtml.png\" alt=\"mediatypes-sendhtml\" width=\"682\" height=\"419\" srcset=\"https:\/\/wordpress.jpcorp.eti.br\/wp-content\/uploads\/2016\/08\/mediatypes-sendhtml.png 682w, https:\/\/wordpress.jpcorp.eti.br\/wp-content\/uploads\/2016\/08\/mediatypes-sendhtml-300x184.png 300w, https:\/\/wordpress.jpcorp.eti.br\/wp-content\/uploads\/2016\/08\/mediatypes-sendhtml-644x396.png 644w\" sizes=\"auto, (max-width: 682px) 100vw, 682px\" \/><\/a>Pronto agora basta configurar uma a\u00e7\u00e3o e adicionar o c\u00f3digo HTML dentro do campo \"Default message\", ai para gerar seu HTML bonitinho fa\u00e7a uma busca no Google que achara v\u00e1rios criadores de c\u00f3digos HTML (<a href=\"http:\/\/www.html.am\/html-editors\/online-html-editor.cfm\">http:\/\/www.html.am\/html-editors\/online-html-editor.cfm)<\/a> (<a href=\"http:\/\/www.quackit.com\/html\/online-html-editor\/\">http:\/\/www.quackit.com\/html\/online-html-editor\/<\/a>).<\/p>\n<p style=\"text-align: justify;\"><a href=\"http:\/\/wordpress.jpcorp.eti.br\/?attachment_id=549\" rel=\"attachment wp-att-549\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-549\" src=\"http:\/\/wordpress.jpcorp.eti.br\/wp-content\/uploads\/2016\/08\/actions-sendhtml.png\" alt=\"actions-sendhtml\" width=\"613\" height=\"582\" srcset=\"https:\/\/wordpress.jpcorp.eti.br\/wp-content\/uploads\/2016\/08\/actions-sendhtml.png 613w, https:\/\/wordpress.jpcorp.eti.br\/wp-content\/uploads\/2016\/08\/actions-sendhtml-300x285.png 300w\" sizes=\"auto, (max-width: 613px) 100vw, 613px\" \/><\/a>E o resultado, com uma tabela simples em HTML:<\/p>\n<p style=\"text-align: justify;\"><a href=\"http:\/\/wordpress.jpcorp.eti.br\/?attachment_id=550\" rel=\"attachment wp-att-550\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-550\" src=\"http:\/\/wordpress.jpcorp.eti.br\/wp-content\/uploads\/2016\/08\/action.png\" alt=\"action\" width=\"868\" height=\"408\" srcset=\"https:\/\/wordpress.jpcorp.eti.br\/wp-content\/uploads\/2016\/08\/action.png 868w, https:\/\/wordpress.jpcorp.eti.br\/wp-content\/uploads\/2016\/08\/action-300x141.png 300w, https:\/\/wordpress.jpcorp.eti.br\/wp-content\/uploads\/2016\/08\/action-768x361.png 768w, https:\/\/wordpress.jpcorp.eti.br\/wp-content\/uploads\/2016\/08\/action-644x303.png 644w\" sizes=\"auto, (max-width: 868px) 100vw, 868px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>E chegou a parte de tipos de m\u00eddia para notifica\u00e7\u00f5es, e-mail no Gmail e Telegram postei aqui as configura\u00e7\u00f5es, por\u00e9m antes de uma requisi\u00e7\u00e3o eu pensei: Pow um e-mail em HTML bonitinho iria ser show e com certeza que ir\u00e3o me solicitar isto! Ent\u00e3o l\u00e1 vai o Jhones analisar, visto que com a conta de&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,48],"tags":[9,50,41],"class_list":["post-545","post","type-post","status-publish","format-standard","hentry","category-linux","category-zabbix","tag-linux","tag-python","tag-zabbix"],"_links":{"self":[{"href":"https:\/\/wordpress.jpcorp.eti.br\/index.php?rest_route=\/wp\/v2\/posts\/545","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.jpcorp.eti.br\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.jpcorp.eti.br\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.jpcorp.eti.br\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.jpcorp.eti.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=545"}],"version-history":[{"count":4,"href":"https:\/\/wordpress.jpcorp.eti.br\/index.php?rest_route=\/wp\/v2\/posts\/545\/revisions"}],"predecessor-version":[{"id":729,"href":"https:\/\/wordpress.jpcorp.eti.br\/index.php?rest_route=\/wp\/v2\/posts\/545\/revisions\/729"}],"wp:attachment":[{"href":"https:\/\/wordpress.jpcorp.eti.br\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.jpcorp.eti.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.jpcorp.eti.br\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}