Exemple #1
0
 def updateMonitor(self, reguIdList):
     """
     function: 写Monitor表 
     args: 无
     return:无
     author: 翟鑫瑞
     """
     if self.result['code'] != 300:
         return
     NAME = self.monitorName
     LOGPATH = self.logPath
     PRODUCT = self.product
     BNS = zmonlib.listToStr(self.serviceName)
     ZCM_ADDR = "tcp://%s:7999" % zmonlib.getZcmIp(PRODUCT, NAME)
     GREP = self.grep.replace('\\', '\\\\')
     GREPV = self.grepv.replace('\\', '\\\\')
     KEY_ID_LIST = []
     VALUE_ID_LIST = []
     REGULAR_ID_LIST = reguIdList
     UITREE = {}
     UICHART = {}
     for node_name in self.nodeList:
         UITREE[node_name] = zmonlib.listToStr(self.nodeList[node_name],
                                               ',')
         KEY_ID_LIST.extend(self.nodeList[node_name])
     for chart in self.chartList:
         VALUE_ID_LIST.append(chart)
         if self.chartList[chart] == 'true':
             UICHART[chart] = 'average'
         else:
             UICHART[chart] = 'sum'
     logging.debug(KEY_ID_LIST)
     KEY_ID_LIST = zmonlib.listToStr(list(set(KEY_ID_LIST)))
     VALUE_ID_LIST = zmonlib.listToStr(list(set(VALUE_ID_LIST)))
     sql = 'update monitor set LOGPATH="%s",BNS="%s",ZCM_ADDR="%s",GREP="%s",GREPV="%s",KEY_ID_LIST="%s", \
            VALUE_ID_LIST="%s",REGULAR_ID_LIST="%s",UITREE="%s",UICHART="%s" where MONITOR_ID=%s' \
            % (LOGPATH,BNS,ZCM_ADDR,GREP,GREPV,KEY_ID_LIST,VALUE_ID_LIST,REGULAR_ID_LIST,str(UITREE),str(UICHART),self.monitorId)
     try:
         result = self.cursor.execute(sql)
         logging.debug('exec sql: %s\n' % sql)
         logging.debug('get result: %s \n' % result)
     except Exception, e:
         self.result = {'code': 400, 'txt': u'exec mysql error: %s' % e}
         return
Exemple #2
0
 def insertMonitor(self, reguIdList):
     """
     function: 写Monitor表 
     args: 无
     return:无
     author: 翟鑫瑞
     """
     NAME = self.monitorName
     BNS = zmonlib.listToStr(self.serviceName)
     LOGPATH = self.logPath
     PRODUCT = self.product
     ZCM_ADDR = "tcp://%s:7999" % zmonlib.getZcmIp(PRODUCT, NAME)
     GREP = self.grep
     GREPV = self.grepv
     KEY_ID_LIST = []
     VALUE_ID_LIST = []
     REGULAR_ID_LIST = reguIdList
     UITREE = {}
     UICHART = {}
     for node_name in self.nodeList:
         UITREE[node_name] = zmonlib.listToStr(self.nodeList[node_name],
                                               ',')
         KEY_ID_LIST.extend(self.nodeList[node_name])
     for chart in self.chartList:
         VALUE_ID_LIST.append(chart)
         if self.chartList[chart] == 'true':
             UICHART[chart] = 'average'
         else:
             UICHART[chart] = 'sum'
     logging.debug(KEY_ID_LIST)
     KEY_ID_LIST = zmonlib.listToStr(list(set(KEY_ID_LIST)))
     VALUE_ID_LIST = zmonlib.listToStr(list(set(VALUE_ID_LIST)))
     sql = "insert into monitor\
         (NAME,LOGPATH,PRODUCT,BNS,ZCM_ADDR,GREP,GREPV,KEY_ID_LIST,VALUE_ID_LIST,REGULAR_ID_LIST,UITREE,UICHART) \
         values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', \"%s\", \"%s\")"                                                                                                % \
         (NAME,LOGPATH,PRODUCT,BNS,ZCM_ADDR,GREP,GREPV,KEY_ID_LIST,VALUE_ID_LIST,REGULAR_ID_LIST,str(UITREE),str(UICHART))
     try:
         result = self.cursor.execute(sql)
         logging.debug('exec sql: %s\n' % sql)
         logging.debug('get result: %s \n' % result)
     except Exception, e:
         self.result = {'code': 400, 'txt': u'exec mysql error: %s' % e}
         return
Exemple #3
0
 def updateMonitor(self,reguIdList):
     """
     function: 写Monitor表 
     args: 无
     return:无
     author: 翟鑫瑞
     """
     if self.result['code'] != 300:
         return
     NAME = self.monitorName
     LOGPATH = self.logPath
     PRODUCT = self.product
     BNS = zmonlib.listToStr(self.serviceName)
     ZCM_ADDR = "tcp://%s:7999" % zmonlib.getZcmIp(PRODUCT, NAME)
     GREP = self.grep.replace('\\','\\\\')
     GREPV = self.grepv.replace('\\','\\\\')
     KEY_ID_LIST = []
     VALUE_ID_LIST = []
     REGULAR_ID_LIST = reguIdList
     UITREE = {}
     UICHART= {}
     for node_name in self.nodeList:
         UITREE[node_name] = zmonlib.listToStr(self.nodeList[node_name],',')
         KEY_ID_LIST.extend(self.nodeList[node_name])
     for chart in self.chartList:
         VALUE_ID_LIST.append(chart)
         if self.chartList[chart] == 'true':
             UICHART[chart] = 'average'
         else:
             UICHART[chart] = 'sum'
     logging.debug(KEY_ID_LIST)
     KEY_ID_LIST = zmonlib.listToStr(list(set(KEY_ID_LIST)))
     VALUE_ID_LIST = zmonlib.listToStr(list(set(VALUE_ID_LIST)))
     sql = 'update monitor set LOGPATH="%s",BNS="%s",ZCM_ADDR="%s",GREP="%s",GREPV="%s",KEY_ID_LIST="%s", \
            VALUE_ID_LIST="%s",REGULAR_ID_LIST="%s",UITREE="%s",UICHART="%s" where MONITOR_ID=%s' \
            % (LOGPATH,BNS,ZCM_ADDR,GREP,GREPV,KEY_ID_LIST,VALUE_ID_LIST,REGULAR_ID_LIST,str(UITREE),str(UICHART),self.monitorId)
     try:
         result = self.cursor.execute(sql)
         logging.debug('exec sql: %s\n' % sql)
         logging.debug('get result: %s \n' % result)
     except Exception, e:
         self.result = {'code':400,'txt':u'exec mysql error: %s' % e}
         return
Exemple #4
0
 def insertMonitor(self,reguIdList):
     """
     function: 写Monitor表 
     args: 无
     return:无
     author: 翟鑫瑞
     """
     NAME = self.monitorName
     BNS = zmonlib.listToStr(self.serviceName)
     LOGPATH = self.logPath
     PRODUCT = self.product
     ZCM_ADDR = "tcp://%s:7999" % zmonlib.getZcmIp(PRODUCT, NAME)
     GREP = self.grep
     GREPV = self.grepv
     KEY_ID_LIST = []
     VALUE_ID_LIST = []
     REGULAR_ID_LIST = reguIdList
     UITREE = {}
     UICHART= {}
     for node_name in self.nodeList:
         UITREE[node_name] = zmonlib.listToStr(self.nodeList[node_name],',')
         KEY_ID_LIST.extend(self.nodeList[node_name])
     for chart in self.chartList:
         VALUE_ID_LIST.append(chart)
         if self.chartList[chart] == 'true':
             UICHART[chart] = 'average'
         else:
             UICHART[chart] = 'sum'
     logging.debug(KEY_ID_LIST)
     KEY_ID_LIST = zmonlib.listToStr(list(set(KEY_ID_LIST)))
     VALUE_ID_LIST = zmonlib.listToStr(list(set(VALUE_ID_LIST)))
     sql = "insert into monitor\
         (NAME,LOGPATH,PRODUCT,BNS,ZCM_ADDR,GREP,GREPV,KEY_ID_LIST,VALUE_ID_LIST,REGULAR_ID_LIST,UITREE,UICHART) \
         values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', \"%s\", \"%s\")" % \
         (NAME,LOGPATH,PRODUCT,BNS,ZCM_ADDR,GREP,GREPV,KEY_ID_LIST,VALUE_ID_LIST,REGULAR_ID_LIST,str(UITREE),str(UICHART))
     try:
         result = self.cursor.execute(sql)
         logging.debug('exec sql: %s\n' % sql)
         logging.debug('get result: %s \n' % result)
     except Exception, e:
         self.result = {'code':400,'txt':u'exec mysql error: %s' % e}
         return
Exemple #5
0
 def reloadMonflow(self):
     product = self.input.get('product')
     ip = zmonlib.getZcmIp(product, '')
     if ip == None:
         return
     port = 7333
     cmd = ['ZMON_RELOAD', '', str(product)]
     try:
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         s.settimeout(1)
         try:
             s.connect((ip,port))  #'*.*.*.*'写上你要接入的IP地址
             s.close()
         except Exception, e:
             logging.exception('send cmd %s to ip: %s, port: %s error: %s' % (cmd, ip, port, e))
             s.close()
             return
         ctx = zmq.Context()
         pub = ctx.socket(zmq.PUB) 
         pub.connect('tcp://%s:%s' % (ip, port))
         pub.setsockopt(zmq.HWM, 1024)
         pub.send_multipart(cmd)
         logging.debug('send reload Monflow')
Exemple #6
0
 def reloadMonflow(self):
     product = self.input.get('product')
     ip = zmonlib.getZcmIp(product, '')
     if ip == None:
         return
     port = 7333
     cmd = ['ZMON_RELOAD', '', str(product)]
     try:
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         s.settimeout(1)
         try:
             s.connect((ip, port))  #'*.*.*.*'写上你要接入的IP地址
             s.close()
         except Exception, e:
             logging.exception('send cmd %s to ip: %s, port: %s error: %s' %
                               (cmd, ip, port, e))
             s.close()
             return
         ctx = zmq.Context()
         pub = ctx.socket(zmq.PUB)
         pub.connect('tcp://%s:%s' % (ip, port))
         pub.setsockopt(zmq.HWM, 1024)
         pub.send_multipart(cmd)
         logging.debug('send reload Monflow')