예제 #1
0
def send_sms(sms_to_list, sms_msg, db_type, application, host, port, level,
             alarm_item, alarm_value, message):
    '''
    sms_to_list:发给谁
    sms_msg:短信内容
    sms_msg='['+level+'] '+db_type+'-'+tags+'-'+server+' '+message+' Time:'+create_time.strftime('%Y-%m-%d %H:%M:%S')
    '''
    '''
    sms_to_list_comma:多个短信接收者,用逗号拼接
    sms_to_list_semicolon:多个短信接收者,用分号拼接
    '''
    sms_to_list_comma = ",".join(sms_to_list)
    sms_to_list_semicolon = ";".join(sms_to_list)
    try:
        ######### you send sms code here ##############
        sms_fetion_user = func.get_option('sms_fetion_user')
        sms_fetion_pass = func.get_option('sms_fetion_pass')
        os.system(
            'fetion --mobile=%s --pwd=%s --to=%s --msg-type=1 --msg-utf8="%s"'
            % (sms_fetion_user, sms_fetion_pass, sms_to_list_comma, sms_msg))
        ###############################################
        return True
    except Exception, e:
        print str(e)
        return False
예제 #2
0
def main():
    logger.info("lepus controller start.")
    monitor = str(func.get_option('monitor'))
    monitor_mysql = str(func.get_option('monitor_mysql'))
    monitor_mongodb = str(func.get_option('monitor_mongodb'))
    monitor_oracle = str(func.get_option('monitor_oracle'))
    monitor_redis = str(func.get_option('monitor_redis'))
    monitor_sqlserver = str(func.get_option('monitor_sqlserver'))
    monitor_os = str(func.get_option('monitor_os'))
    alarm = str(func.get_option('alarm'))
    frequency_monitor = func.get_option('frequency_monitor')
    frequency_monitor_alarm = int(frequency_monitor)+10

    joblist = []
    if monitor=="1":
        if monitor_mysql=="1":
            job = Process(target = job_run, args = ('check_mysql',frequency_monitor))
            joblist.append(job)
            job.start()

        time.sleep(3)
        if monitor_oracle=="1":
            job = Process(target = job_run, args = ('check_oracle',frequency_monitor))
            joblist.append(job)
            job.start()

        time.sleep(3)
        if monitor_mongodb=="1":
            job = Process(target = job_run, args = ('check_mongodb',frequency_monitor))
            joblist.append(job)
            job.start()

        time.sleep(3)
        if monitor_redis=="1":
            job = Process(target = job_run, args = ('check_redis',frequency_monitor))
            joblist.append(job)
            job.start()

        time.sleep(3)
        if monitor_sqlserver=="1":
            job = Process(target = job_run, args = ('check_sqlserver',frequency_monitor))
            joblist.append(job)
            job.start()

        time.sleep(3)
        if monitor_os=="1":
            job = Process(target = job_run, args = ('check_os',frequency_monitor))
            joblist.append(job)
            job.start()

        time.sleep(3)
        if alarm=="1":
            job = Process(target = job_run, args = ('alarm',frequency_monitor_alarm))
            joblist.append(job)
            job.start()    

        for job in joblist:
            job.join();

    logger.info("lepus controller finished.")
예제 #3
0
def main():
    logger.info("wlblazers controller start.")
    monitor = str(func.get_option('monitor'))
    monitor_mysql = str(func.get_option('monitor_mysql'))
    monitor_mongodb = str(func.get_option('monitor_mongodb'))
    monitor_oracle = str(func.get_option('monitor_oracle'))
    monitor_redis = str(func.get_option('monitor_redis'))
    monitor_sqlserver = str(func.get_option('monitor_sqlserver'))
    monitor_os = str(func.get_option('monitor_os'))
    alert = str(func.get_option('alert'))
    frequency_monitor = func.get_option('frequency_monitor')
    frequency_alert = 60

    joblist = []
    if monitor == "1":
        if monitor_mysql == "1":
            job = Process(target=job_run,
                          args=('check_mysql', frequency_monitor))
            joblist.append(job)
            job.start()

        time.sleep(3)
        if monitor_oracle == "1":
            job = Process(target=job_run,
                          args=('check_oracle', frequency_monitor))
            joblist.append(job)
            job.start()

        time.sleep(3)
        if monitor_sqlserver == "1":
            job = Process(target=job_run,
                          args=('check_sqlserver', frequency_monitor))
            joblist.append(job)
            job.start()

        time.sleep(3)
        if monitor_os == "1":
            job = Process(target=job_run, args=('check_os', frequency_monitor))
            joblist.append(job)
            job.start()

        time.sleep(3)
        if alert == "1":
            job = Process(target=job_run, args=('alert_main', frequency_alert))
            joblist.append(job)
            job.start()

        time.sleep(3)
        job = Process(target=job_run, args=('clean_history', 3600))
        joblist.append(job)
        job.start()

        for job in joblist:
            job.join()

    logger.info("wlblazers controller finished.")
예제 #4
0
def main():
    logger.info("lepus controller start.")
    monitor = func.get_option('monitor')
    monitor_mysql = func.get_option('monitor_mysql')
    monitor_mongodb = func.get_option('monitor_mongodb')
    monitor_oracle = func.get_option('monitor_oracle')
    monitor_redis = func.get_option('monitor_redis')
    monitor_os = func.get_option('monitor_os')
    alarm = func.get_option('alarm')
    frequency_monitor = func.get_option('frequency_monitor')
    frequency_monitor_alarm = int(frequency_monitor)+10

    joblist = []
    if monitor=="1":
        if monitor_mysql=="1":
            job = Process(target = job_run, args = ('check_mysql',frequency_monitor))
            joblist.append(job)
            job.start()

        time.sleep(3)
        if monitor_oracle=="1":
            job = Process(target = job_run, args = ('check_oracle',frequency_monitor))
            joblist.append(job)
            job.start()

        time.sleep(3)
        if monitor_mongodb=="1":
            job = Process(target = job_run, args = ('check_mongodb',frequency_monitor))
            joblist.append(job)
            job.start()

        time.sleep(3)
        if monitor_redis=="1":
            job = Process(target = job_run, args = ('check_redis',frequency_monitor))
            joblist.append(job)
            job.start()

        time.sleep(3)
        if monitor_os=="1":
            job = Process(target = job_run, args = ('check_os',frequency_monitor))
            joblist.append(job)
            job.start()

        time.sleep(3)
        if alarm=="1":
            job = Process(target = job_run, args = ('alarm',frequency_monitor_alarm))
            joblist.append(job)
            job.start()    

        for job in joblist:
            job.join();

    logger.info("lepus controller finished.")
예제 #5
0
def main():
    monitor_os_method = func.get_option("monitor_os_method")
    cmdFile = "%s/check_os_%s.py" % (scDir, monitor_os_method)
    os.system("python %s" % (cmdFile))

    osTables = ('os_status', 'os_net', 'os_disk', 'os_diskio')
    for osTable in osTables:
        func.mysql_exec(
            'DELETE s FROM %s AS s WHERE s.ip NOT IN (SELECT v.host FROM v_monitor_host AS v)'
            % (osTable))
예제 #6
0
파일: sendsms_fx.py 프로젝트: crjfans/lepus
def send_sms(sms_to_list,sms_msg,db_type,application,host,port,level,alarm_item,alarm_value,message):
    '''
    sms_to_list:发给谁
    sms_msg:短信内容
    sms_msg='['+level+'] '+db_type+'-'+tags+'-'+server+' '+message+' Time:'+create_time.strftime('%Y-%m-%d %H:%M:%S')
    '''
    '''
    sms_to_list_comma:多个短信接收者,用逗号拼接
    sms_to_list_semicolon:多个短信接收者,用分号拼接
    '''
    sms_to_list_comma = ",".join(sms_to_list)
    sms_to_list_semicolon = ";".join(sms_to_list)
    try:
        ######### you send sms code here ##############
        sms_fetion_user = func.get_option('sms_fetion_user')
        sms_fetion_pass = func.get_option('sms_fetion_pass')
        os.system('fetion --mobile=%s --pwd=%s --to=%s --msg-type=1 --msg-utf8="%s"' %(sms_fetion_user,sms_fetion_pass,sms_to_list_comma,sms_msg)) 
        ###############################################
        return True
    except Exception, e:
        print str(e)
        return False
예제 #7
0
#!/usr/bin/env python
# -*- coding: utf8 -*-
from datetime import *
import sys
path='./include'
sys.path.insert(0,path)
import functions as func

send_mail_to_list = func.get_option('send_mail_to_list')
mailto_list=send_mail_to_list.split(';')

result = func.send_mail(mailto_list," I hope you can learn","Beautiful Day")
print result
if result:
    send_mail_status = "success"
else:
    send_mail_status = "fail"
print "send_mail_status:"+send_mail_status
예제 #8
0
파일: sendmail.py 프로젝트: hisery/Lepus-1
#!/bin/env python
#-*-coding:utf-8-*-

import string
import sys 
reload(sys) 
sys.setdefaultencoding('utf8')
import ConfigParser
import smtplib
from email.mime.text import MIMEText
from email.message import Message
from email.header import Header
import functions as func


mail_host = func.get_option('smtp_host')
mail_port = int(func.get_option('smtp_port'))
mail_user = func.get_option('smtp_user')
mail_pass = func.get_option('smtp_pass')
mail_send_from = func.get_option('mailfrom')


def send_mail(to_list,sub,content):
    '''
    to_list:发给谁
    sub:主题
    content:内容
    send_mail("*****@*****.**","sub","content")
    '''
    #me=mail_user+"<</span>"+mail_user+"@"+mail_postfix+">"
    me=mail_send_from
예제 #9
0
def main():
    logger.info("camelbell controller start.")
    monitor = str(func.get_option('monitor'))
    monitor_mysql = str(func.get_option('monitor_mysql'))
    monitor_mysql_bigtable = str(func.get_option('monitor_mysql_bigtable'))
    monitor_mongodb = str(func.get_option('monitor_mongodb'))
    monitor_oracle = str(func.get_option('monitor_oracle'))
    monitor_redis = str(func.get_option('monitor_redis'))
    monitor_os = str(func.get_option('monitor_os'))
    alarm = str(func.get_option('alarm'))
    frequency_monitor = func.get_option('frequency_monitor')
    frequency_monitor_alarm = int(frequency_monitor) + 10
    frequency_sync_os = func.get_option('frequency_sync_os')

    joblist = []
    if monitor == "1":
        #
        logger.info("[BBQ] sync_os")
        job = Process(target=job_run, args=('sync_os', frequency_sync_os))
        joblist.append(job)
        job.start()

        logger.info("[BBQ]monitor mysql %s" % (monitor_mysql))
        if monitor_mysql == "1":
            job = Process(target=job_run,
                          args=('check_mysql', frequency_monitor))
            joblist.append(job)
            job.start()

        if monitor_oracle == "1":
            time.sleep(3)
            job = Process(target=job_run,
                          args=('check_oracle', frequency_monitor))
            joblist.append(job)
            job.start()

        if monitor_mongodb == "1":
            time.sleep(3)
            job = Process(target=job_run,
                          args=('check_mongodb', frequency_monitor))
            joblist.append(job)
            job.start()

        if monitor_redis == "1":
            time.sleep(3)
            job = Process(target=job_run,
                          args=('check_redis', frequency_monitor))
            joblist.append(job)
            job.start()

        if monitor_os == "1":
            time.sleep(3)
            freq_os = 60 * 5
            job = Process(target=job_run, args=('check_os', freq_os))
            joblist.append(job)
            job.start()

        if alarm == "1":
            time.sleep(3)
            job = Process(target=job_run,
                          args=('alarm', frequency_monitor_alarm))
            joblist.append(job)
            job.start()

        for job in joblist:
            job.join()

    logger.info("camelbell controller finished.")
예제 #10
0
def send_alert_media():
    sql = """SELECT id, 
										tags,
										host,
										port,
										create_time,
										db_type,
										alert_item,
										alert_value,
										LEVEL,
										message,
										send_mail,
										send_mail_to_list,
										send_mail_status,
										send_sms,
										send_sms_to_list,
										send_sms_status,
										send_wx,
										send_wx_status
									FROM alerts 
									where (send_mail = 1 and send_mail_status = 0)
									  or (send_sms = 1 and send_sms_status = 0)
									  or (send_wx = 1 and send_wx_status = 0) """
    result = func.mysql_query(sql)
    if result:
        send_alarm_mail = func.get_option('send_alarm_mail')
        send_alarm_sms = func.get_option('send_alarm_sms')
        send_alarm_wx = func.get_option('send_alarm_wx')

        if int(send_alarm_wx) == 1:
            l_time = time.strftime("%H", time.localtime())
            if l_time == "12":
                send_wx_status = 0
                wx_status = func.check_wx_status(send_alarm_wx)
                if wx_status:
                    wx_msg = '[Normal]WeChat send status is OK!'
                    send_res = sendwx.send_wx(wx_msg)
                    print "send_res: %s" % (send_res)
                    if send_res:
                        send_wx_status = 1

                    try:
                        sql = "update media_status set send_wx_status = %s, create_time=NOW() where date = DATE_FORMAT(NOW(),'%%Y-%%m-%%d');" % (
                            send_wx_status)
                        print sql
                        func.mysql_exec(sql, '')
                    except Exception, e:
                        print e

        for line in result:
            alert_id = line[0]
            tags = line[1]
            host = line[2]
            port = line[3]
            create_time = line[4]
            db_type = line[5]
            alert_item = line[6]
            alert_value = line[7]
            level = line[8]
            message = line[9]
            send_mail = line[10]
            send_mail_to_list = line[11]
            send_mail_status = line[12]
            send_sms = line[13]
            send_sms_to_list = line[14]
            send_sms_status = line[15]
            send_wx = line[16]
            send_wx_status = line[17]

            if port:
                server = host + ':' + port
            else:
                server = host

            if send_mail_to_list:
                mail_to_list = send_mail_to_list.split(';')
            else:
                send_mail = 0

            if send_sms_to_list:
                sms_to_list = send_sms_to_list.split(';')
            else:
                send_sms = 0

            #logger.info("alert_id: %s" %(alert_id))
            if int(send_alarm_mail) == 1:
                if send_mail == 1 and send_mail_status == 0:
                    mail_subject = '[' + level + '] ' + db_type + '-' + tags + '-' + server + ' ' + message + ' Time:' + create_time.strftime(
                        '%Y-%m-%d %H:%M:%S')
                    mail_content = """
                         Type: %s\n<br/>
                         Tags: %s\n<br/> 
                         Host: %s:%s\n<br/> 
                        Level: %s\n<br/>
                         Item: %s\n<br/>  
                        Value: %s\n<br/> 
                       Message: %s\n<br/> 
                         
                    """ % (db_type, tags, host, port, level, alert_item,
                           alert_value, message)
                    logger.info("begin mail_subject: %s" % (mail_subject))
                    result = sendmail.send_mail(mail_to_list, mail_subject,
                                                mail_content)
                    logger.info("end mail_subject: %s" % (mail_subject))
                    if result:
                        send_mail_status = 1
                        func.mysql_exec(
                            "update alerts set send_mail_status = 1 where id=%s"
                            % (alert_id), "")
                    else:
                        send_mail_status = 0
                else:
                    send_mail_status = 0
            else:
                send_mail_status = 0

            if int(send_alarm_sms) == 1:
                if send_sms == 1 and send_sms_status == 0:
                    sms_msg = '[' + level + '] ' + db_type + '-' + tags + '-' + server + ' ' + message + ' Time:' + create_time.strftime(
                        '%Y-%m-%d %H:%M:%S')
                    send_sms_type = func.get_option('smstype')
                    if send_sms_type == 'fetion':
                        result = sendsms_fx.send_sms(sms_to_list, sms_msg,
                                                     db_type, tags, host, port,
                                                     level, alert_item,
                                                     alert_value, message)
                    else:
                        result = sendsms_api.send_sms(sms_to_list, sms_msg,
                                                      db_type, tags, host,
                                                      port, level, alert_item,
                                                      alert_value, message)

                    if result:
                        send_sms_status = 1
                        func.mysql_exec(
                            "update alerts set send_sms_status = 1 where id=%s"
                            % (alert_id), "")
                    else:
                        send_sms_status = 0
                else:
                    send_sms_status = 0
            else:
                send_sms_status = 0

            if int(send_alarm_wx) == 1:
                if send_wx == 1 and send_wx_status == 0:
                    wx_msg = '[' + level + '] ' + db_type + '-' + tags + '-' + server + ' ' + message + ' Time:' + create_time.strftime(
                        '%Y-%m-%d %H:%M:%S')

                    result = sendwx.send_wx(wx_msg)

                    if result:
                        send_wx_status = 1
                        func.mysql_exec(
                            "update alerts set send_wx_status = 1 where id=%s"
                            % (alert_id), "")
                    else:
                        send_wx_status = 0
                else:
                    send_wx_status = 0
            else:
                send_wx_status = 0
예제 #11
0
from multiprocessing import Process;
import json
import re

srvKey='monitor_server'
dbhost = func.get_config(srvKey,'host')
dbport = func.get_config(srvKey,'port')
dbuser = func.get_config(srvKey,'user')
dbpasswd = func.get_config(srvKey,'passwd')
dbname = func.get_config(srvKey,'dbname')

cnfKey='monitor_os'
cpus = int(func.get_config(cnfKey,'cpus'))
exeTimeout = int(func.get_config(cnfKey,'timeout'))

min_interval = func.get_option('min_interval')

DEFAULT_ZBSRV_KEY = "DBA"

itemTabs = {}
itemTabs['os'] = 'os_status'
itemTabs['disk'] = 'os_disk'
itemTabs['net'] = 'os_net'
itemTabs['diskio'] = 'os_diskio'


def upd_zbitem_time(stat_item_name, last_stat_time):
    updSql = "UPDATE zabbix_item SET last_stat_time=%s WHERE stat_item_name='%s'" % (last_stat_time, stat_item_name)
    func.mysql_exec(updSql)

'''
예제 #12
0
#!/bin/env python
#-*-coding:utf-8-*-

import string
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import ConfigParser
import smtplib
from email.mime.text import MIMEText
from email.message import Message
from email.header import Header
import functions as func

mail_host = func.get_option('smtp_host')
mail_port = int(func.get_option('smtp_port'))
mail_user = func.get_option('smtp_user')
mail_pass = func.get_option('smtp_pass')
mail_send_from = func.get_option('mailfrom')

mail_to_list_common = func.get_option('send_mail_to_list')


def send_mail(to_list, sub, content):
    '''
    to_list:发给谁
    sub:主题
    content:内容
    send_mail("*****@*****.**","sub","content")
    '''
    #me=mail_user+"<</span>"+mail_user+"@"+mail_postfix+">"
예제 #13
0
def main(hosts=None):
    dohosts = None
    if hosts != None:
        dohosts = hosts.split(",")
    #get mysql servers list
    #servers = func.mysql_query('select id,host,port,username,password,tags from db_servers_mysql where is_delete=0 and monitor=1;')
    servers = func.mysql_query(
        'select id,host,port,tags from db_servers_mysql where is_delete=0 and monitor=1 order by rand();'
    )

    logger.info("check mysql controller started.")

    #++ guoqi
    exeTimeout = 60
    cnfKey = "monitor_mysql"
    username = func.get_config(cnfKey, 'user')
    password = func.get_config(cnfKey, 'passwd')
    min_interval = func.get_option('min_interval')

    if servers:
        plist = []
        for row in servers:
            (server_id, host, port, tags) = row
            if dohosts != None and dohosts.count(host) <= 0:
                continue
            check_mysql(host, port, username, password, server_id, tags)
            continue
            plist = []
            (server_id, host, port, tags) = row
            p = Process(target=check_mysql,
                        args=(host, port, username, password, server_id, tags))
            p.start()

            i = 0
            while (i < 10):
                time.sleep(1)
                i += 1
                if p.is_alive():
                    continue
            p.join(timeout=2)
        '''
	for p in plist:
	    p.start()
	for p in plist:
	    p.join(timeout=exeTimeout)
	'''
    else:
        logger.warning("check mysql: not found any servers")

    func.mysql_exec(
        'DELETE ds FROM mysql_replication AS ds, (SELECT s.id,d.host FROM mysql_replication AS s LEFT JOIN db_servers_mysql AS d  ON d.is_delete=0 AND d.monitor=1 AND s.host=d.host AND s.port=d.port HAVING d.`host` IS NULL) AS t  WHERE ds.id=t.id'
    )
    func.mysql_exec(
        'DELETE ds FROM mysql_status AS ds, (SELECT s.id,d.host FROM mysql_status AS s LEFT JOIN db_servers_mysql AS d  ON d.is_delete=0 AND d.monitor=1 AND s.host=d.host AND s.port=d.port HAVING d.`host` IS NULL) AS t  WHERE ds.id=t.id'
    )
    func.mysql_exec(
        'DELETE ds FROM db_status AS ds, (SELECT s.id,d.host FROM db_status AS s LEFT JOIN db_servers_mysql AS d  ON d.is_delete=0 AND d.monitor=1 AND s.host=d.host AND s.port=d.port  WHERE db_type="mysql"  HAVING d.`host` IS NULL) AS t  WHERE ds.id=t.id'
    )
    func.mysql_exec(
        'update mysql_status set connect=0,create_time=now()  where create_time<date_sub(now(), interval %s second)'
        % (min_interval))
    func.mysql_exec(
        'update mysql_replication set slave_io_run="No",slave_sql_run="No",create_time=now()  where create_time<date_sub(now(), interval %s second)'
        % (min_interval))
    logger.info("check mysql controller finished.")
예제 #14
0
#!/usr/bin/env python
# -*- coding: utf8 -*-
from datetime import *
import os
import sys
path='./include'
sys.path.insert(0,path)
import functions as func

send_sms_to_list = func.get_option('send_sms_to_list')
sms_to_list=send_sms_to_list.split(';')
sms_to_list_comma = ",".join(sms_to_list)
sms_fetion_user = func.get_option('sms_fetion_user')
sms_fetion_pass = func.get_option('sms_fetion_pass')
sms_msg = "Hello Lepus!"
result = os.system('fetion --mobile=%s --pwd=%s --to=%s --msg-type=1  --msg-utf8="%s" --debug' %(sms_fetion_user,sms_fetion_pass,sms_to_list_comma,sms_msg))
print result
예제 #15
0
파일: KanaTore.py 프로젝트: nvplus/KanaTore
import functions, json

print()
print(43 * "-")
print("Welcome to KanaTore! | かなトレへようくそ!")
print(43 * "-")

start = (input("Would you like to start a new game? (y/n): ")[0:1]).lower()

while start == "y":
    option = functions.get_option()

    start = functions.main_game(option)
예제 #16
0
import string
import time
import datetime
import MySQLdb
import logging
import logging.config
logging.config.fileConfig("etc/logger.ini")
logger = logging.getLogger("alert_sqlserver")
path = './include'
sys.path.insert(0, path)
import functions as func
import sendmail
import sendsms_fx
import sendsms_api

send_mail_max_count = func.get_option('send_mail_max_count')
send_mail_sleep_time = func.get_option('send_mail_sleep_time')
mail_to_list_common = func.get_option('send_mail_to_list')

send_sms_max_count = func.get_option('send_sms_max_count')
send_sms_sleep_time = func.get_option('send_sms_sleep_time')
sms_to_list_common = func.get_option('send_sms_to_list')

g_alert = str(func.get_option('alert'))


#################################################################################################
def gen_alert_sqlserver_status(server_id):
    if g_alert != "1":
        return -1
예제 #17
0
#!/usr/bin/env python
# -*- coding: utf8 -*-
from datetime import *
import sys
path='./include'
sys.path.insert(0,path)
import functions as func

mail_to_list = func.get_option('mail_to_list')
mailto_list=mail_to_list.split(';')

result = func.send_mail(mailto_list," I hope you can learn","Beautiful Day")
print result
if result:
    send_mail_status = "success"
else:
    send_mail_status = "fail"
print "send_mail_status:"+send_mail_status
예제 #18
0
#!/usr/bin/env python
# -*- coding: utf8 -*-
from datetime import *
import sys
path = './include'
sys.path.insert(0, path)
import functions as func

send_mail_to_list = func.get_option('send_mail_to_list')
mailto_list = send_mail_to_list.split(';')

result = func.send_mail(mailto_list, " I hope you can learn", "Beautiful Day")
print result
if result:
    send_mail_status = "success"
else:
    send_mail_status = "fail"
print "send_mail_status:" + send_mail_status
예제 #19
0
def send_alert_mail(server_id, host):
    sql = """SELECT id, 
										tags,
										host,
										port,
										create_time,
										db_type,
										alert_item,
										alert_value,
										LEVEL,
										message,
										send_mail,
										send_mail_to_list,
										send_mail_status,
										send_sms,
										send_sms_to_list,
										send_sms_status
									FROM alerts 
									where server_id = %s
									  and host = '%s' 
									  and ((send_mail = 1 and send_mail_status = 0)
									  or (send_sms = 1 and send_sms_status = 0)) """ % (server_id, host)
    result = func.mysql_query(sql)
    if result:
        send_alarm_mail = func.get_option('send_alarm_mail')
        send_alarm_sms = func.get_option('send_alarm_sms')
        for line in result:
            alert_id = line[0]
            tags = line[1]
            host = line[2]
            port = line[3]
            create_time = line[4]
            db_type = line[5]
            alert_item = line[6]
            alert_value = line[7]
            level = line[8]
            message = line[9]
            send_mail = line[10]
            send_mail_to_list = line[11]
            send_mail_status = line[12]
            send_sms = line[13]
            send_sms_to_list = line[14]
            send_sms_status = line[15]

            if port:
                server = host + ':' + port
            else:
                server = host

            if send_mail_to_list:
                mail_to_list = send_mail_to_list.split(';')
            else:
                send_mail = 0

            if send_sms_to_list:
                sms_to_list = send_sms_to_list.split(';')
            else:
                send_sms = 0

            #logger.info("alert_id: %s" %(alert_id))
            if int(send_alarm_mail) == 1:
                if int(send_mail) == 1:
                    mail_subject = '[' + level + '] ' + db_type + '-' + tags + '-' + server + ' ' + message + ' Time:' + create_time.strftime(
                        '%Y-%m-%d %H:%M:%S')
                    mail_content = """
                         Type: %s\n<br/>
                         Tags: %s\n<br/> 
                         Host: %s:%s\n<br/> 
                        Level: %s\n<br/>
                         Item: %s\n<br/>  
                        Value: %s\n<br/> 
                       Message: %s\n<br/> 
                         
                    """ % (db_type, tags, host, port, level, alert_item,
                           alert_value, message)
                    result = sendmail.send_mail(mail_to_list, mail_subject,
                                                mail_content)
                    if result:
                        send_mail_status = 1
                    else:
                        send_mail_status = 0
                else:
                    send_mail_status = 0
            else:
                send_mail_status = 0

            try:
                sql = "update alerts set send_mail_status = %s, send_sms_status = %s where id = %s; "
                param = (send_mail_status, send_sms_status, alert_id)
                func.mysql_exec(sql, param)
            except Exception, e:
                print e