<s> import json <EOL> try : <EOL> from urlparse import urljoin <EOL> except ImportError : <EOL> from urllib . parse import urljoin <EOL> from tornado import gen , httpclient as hc <EOL> from graphite_beacon . handlers import AbstractHandler , LOGGER <EOL> class VictorOpsHandler ( AbstractHandler ) : <EOL> name = '<STR_LIT>' <EOL> def init_handler ( self ) : <EOL> self . url = self . options . get ( '<STR_LIT>' ) <EOL> assert self . url , '<STR_LIT>' <EOL> self . routing_key = self . options . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . url = urljoin ( self . url , self . routing_key ) <EOL> self . client = hc . AsyncHTTPClient ( ) <EOL> @ gen . coroutine <EOL> def notify ( self , level , alert , value , target = None , ntype = None , rule = None ) : <EOL> LOGGER . debug ( "<STR_LIT>" , self . name , level ) <EOL> message = self . get_short ( level , alert , value , target = target , ntype = ntype , rule = rule ) <EOL> data = { '<STR_LIT>' : alert . name , '<STR_LIT>' : message , '<STR_LIT>' : level } <EOL> if target : <EOL> data [ '<STR_LIT:target>' ] = target <EOL> if rule : <EOL> data [ '<STR_LIT>' ] = rule [ '<STR_LIT>' ] <EOL> body = json . dumps ( data ) <EOL> headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' } <EOL> yield self . client . fetch ( self . url , method = "<STR_LIT:POST>" , body = body , headers = headers ) </s>
