def run(self): while 1: item = self.queue.get(True) s_data = dict() s_item = item.split('^') if s_item[0] == "notification": s_data['type'] = s_item[0] s_data['host_name'] = s_item[1] s_data['notification_type'] = s_item[2] s_data['output'] = s_item[3] s_data['reason_type'] = s_item[4] s_data['service_description'] = s_item[5] s_data['state'] = s_item[6] s_data['from'] = 'nagios' #check md5 signutare for "host_name + service_description + state" #to verify that remote api server has processed this message. md5_str = s_item[1] + s_item[5] + s_item[6] msg_md5 = md5(md5_str).hexdigest() return_code = self.check_md5(msg_md5) # return code 2 and 1 will be use in the future if return_code == '2': break elif return_code == '1': break else: print s_data url = URL_POST_DATA data = s_data http_client(url, data)
def do_send_http(content): # type: moniting if content['notification_type'] == 1: http_client(URL_POST_DATA,content) # type: notification elif content['notification_type'] == 0: # if state is success, ignore it. if content['state'] !=0: http_client(URL_POST_DATA,content)
def run(self): while 1: try: resp = http_client(self.url) try: db = shelve.open('instances.dat','c') db['data'] = eval(resp) finally: db.close() except Exception,e: logger.exception(e) time.sleep(300)
client1.send('SET allow_experimental_live_view = 1') client1.expect(prompt) client1.send('DROP TABLE IF EXISTS test.lv') client1.expect(prompt) client1.send(' DROP TABLE IF EXISTS test.mt') client1.expect(prompt) client1.send( 'CREATE TABLE test.mt (a Int32) Engine=MergeTree order by tuple()') client1.expect(prompt) client1.send('CREATE LIVE VIEW test.lv AS SELECT sum(a) FROM test.mt') client1.expect(prompt) try: with http_client( { 'method': 'GET', 'url': '/?allow_experimental_live_view=1&query=WATCH%20test.lv' }, name='client2>', log=log) as client2: client2.expect('.*0\t1\n') client1.send('INSERT INTO test.mt VALUES (1),(2),(3)') client1.expect(prompt) client2.expect('.*6\t2\n') finally: client1.send('DROP TABLE test.lv') client1.expect(prompt) client1.send('DROP TABLE test.mt') client1.expect(prompt)
client1.send("DROP TABLE IF EXISTS test.lv") client1.expect(prompt) client1.send(" DROP TABLE IF EXISTS test.mt") client1.expect(prompt) client1.send( "CREATE TABLE test.mt (a Int32) Engine=MergeTree order by tuple()") client1.expect(prompt) client1.send("CREATE LIVE VIEW test.lv AS SELECT sum(a) FROM test.mt") client1.expect(prompt) try: with http_client( { "method": "GET", "url": "/?allow_experimental_live_view=1&query=WATCH%20test.lv%20EVENTS", }, name="client2>", log=log, ) as client2: client2.expect(".*1\n") client1.send("INSERT INTO test.mt VALUES (1),(2),(3)") client1.expect(prompt) client2.expect(".*2\n") finally: client1.send("DROP TABLE test.lv") client1.expect(prompt) client1.send("DROP TABLE test.mt") client1.expect(prompt)
def check_md5(self,msg): url = URL_CHECK_MD5 data = {'data':msg} return http_client(url, data)
client1.send("DROP TABLE IF EXISTS test.lv") client1.expect(prompt) client1.send(" DROP TABLE IF EXISTS test.mt") client1.expect(prompt) client1.send( "CREATE TABLE test.mt (a Int32) Engine=MergeTree order by tuple()") client1.expect(prompt) client1.send("CREATE LIVE VIEW test.lv AS SELECT sum(a) FROM test.mt") client1.expect(prompt) with http_client( { "method": "GET", "url": "/?allow_experimental_live_view=1&live_view_heartbeat_interval=1&query=WATCH%20test.lv%20EVENTS%20FORMAT%20JSONEachRowWithProgress", }, name="client2>", log=log, ) as client2: client2.expect( '{"progress":{"read_rows":"1","read_bytes":"8","written_rows":"0","written_bytes":"0","total_rows_to_read":"0"}}\n', escape=True, ) client2.expect('{"row":{"version":"1"}', escape=True) client2.expect( '{"progress":{"read_rows":"1","read_bytes":"8","written_rows":"0","written_bytes":"0","total_rows_to_read":"0"}}', escape=True, ) # heartbeat is provided by progress message client2.expect(
client1.send('DROP TABLE IF EXISTS test.lv') client1.expect(prompt) client1.send(' DROP TABLE IF EXISTS test.mt') client1.expect(prompt) client1.send( 'CREATE TABLE test.mt (a Int32) Engine=MergeTree order by tuple()') client1.expect(prompt) client1.send('CREATE LIVE VIEW test.lv AS SELECT sum(a) FROM test.mt') client1.expect(prompt) with http_client( { 'method': 'GET', 'url': '/?live_view_heartbeat_interval=1&query=WATCH%20test.lv%20FORMAT%20JSONEachRowWithProgress' }, name='client2>', log=log) as client2: client2.expect('"progress".*', ) client2.expect('{"row":{"sum(a)":"0","_version":"1"}}\n', escape=True) client2.expect('"progress".*\n') # heartbeat is provided by progress message client2.expect('"progress".*\n') client1.send('INSERT INTO test.mt VALUES (1),(2),(3)') client1.expect(prompt) client2.expect('"progress".*"read_rows":"2".*\n') client2.expect('{"row":{"sum(a)":"6","_version":"2"}}\n', escape=True)
#log=sys.stdout with client(name='client1>', log=log) as client1: client1.expect(prompt) client1.send('DROP TABLE IF EXISTS test.lv') client1.expect(prompt) client1.send(' DROP TABLE IF EXISTS test.mt') client1.expect(prompt) client1.send( 'CREATE TABLE test.mt (a Int32) Engine=MergeTree order by tuple()') client1.expect(prompt) client1.send('CREATE LIVE VIEW test.lv AS SELECT sum(a) FROM test.mt') client1.expect(prompt) with http_client({ 'method': 'GET', 'url': '/?query=WATCH%20test.lv' }, name='client2>', log=log) as client2: client2.expect('.*0\t1\n') client1.send('INSERT INTO test.mt VALUES (1),(2),(3)') client1.expect(prompt) client2.expect('.*6\t2\n') client1.send('DROP TABLE test.lv') client1.expect(prompt) client1.send('DROP TABLE test.mt') client1.expect(prompt)