You are not logged in.

#1 2015-11-21 12:54:43

Knight
Member
From: ShenZhen/Asia
Registered: 2015-11-19
Posts: 18

How to modify the zabbix script?

I use zabbix as a monitor, but i have a problem, when the zabbix send Alarm email,then the email would send by SMS to my iphone. If the email title is Japanese or Chinese. the sms is Disorder Code. Here is the scripts,how to modify it?

#!/usr/bin/python26
#coding:utf-8
import smtplib
from email.mime.text import MIMEText
import sys
mail_host = 'smtp.189.cn'
mail_user = 'Tom_a'
mail_pass = '123456'
mail_postfix = '189.cn'
def send_mail(to_list,subject,content):
  me = mail_user+"<"+mail_user+"@"+mail_postfix+">"
  msg = MIMEText(content,_subtype='plain',_charset='utf-8')
  msg['Subject'] = subject
  msg['From'] = me
  msg['to'] = to_list
  try:
    s = smtplib.SMTP()
    s.connect(mail_host)
    s.login(mail_user,mail_pass)
    s.sendmail(me,to_list,msg.as_string())
    s.close()
    return True
  except Exception,e:
    print str(e)
    return False
if __name__ == "__main__":
  send_mail(sys.argv[1], sys.argv[2], sys.argv[3])
                                               

Last edited by Knight (2015-11-21 12:55:15)

Offline

#2 2015-11-22 16:31:05

Knight
Member
From: ShenZhen/Asia
Registered: 2015-11-19
Posts: 18

Re: How to modify the zabbix script?

No one know how to modify?

Offline

#3 2015-11-22 16:43:31

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,774

Re: How to modify the zabbix script?

I am afraid I don't understand what you are trying to do.  What you shared with us is a Python program that sends an email to tom_a@189.cn.  Where did that came from?  I am not familiar with zabbix. 
That file has many things hard coded into it.  Mail servers, user names, passwords.  Are those your credentials (and if so, I hope not your real credentials, otherwise you may want to change your password).

So, a naive answer might be to open the file in your favorite editor (emacs, nano, whatever) and update the credentials to your user name, mail server, password, mail domain, etc....


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#4 2015-11-23 09:18:20

Knight
Member
From: ShenZhen/Asia
Registered: 2015-11-19
Posts: 18

Re: How to modify the zabbix script?

it is not my real credentials,when the email was received.it would send to my iphone autoly and free.I just do it.Thank you for your answer.

ewaller wrote:

I am afraid I don't understand what you are trying to do.  What you shared with us is a Python program that sends an email to tom_a@189.cn.  Where did that came from?  I am not familiar with zabbix. 
That file has many things hard coded into it.  Mail servers, user names, passwords.  Are those your credentials (and if so, I hope not your real credentials, otherwise you may want to change your password).

So, a naive answer might be to open the file in your favorite editor (emacs, nano, whatever) and update the credentials to your user name, mail server, password, mail domain, etc....

Offline

#5 2015-11-23 10:29:19

mauritiusdadd
Member
From: Benevento, Italy
Registered: 2013-10-27
Posts: 776

Re: How to modify the zabbix script?

I never used zabbix but if I understand correctly, you use the script to send an email to your(?) zabbix server which in turn forwards the incoming email to your phone trough SMS.

If it's so, then the problem could be the MIMEText function, which encodes the the text if it contains Unicode characters (see https://docs.python.org/2/library/email … t.MIMEText). Try sending a message without encoding it (see here for a basic example https://docs.python.org/2/library/smtpl … tp-example)?

However, if zabbix receive the email correctly, then the problem could be between the zabbix server and your phone (does your phone actually support Unicode SMSes?).


About me - github

-- When you have eliminated the impossible, whatever remains, however improbable, must be the truth -- Spock | Sherlock Holmes

Offline

Board footer

Powered by FluxBB