def send_msg_v2(module, token, room, msg_from, msg, msg_format='text', color='yellow', notify=False, api=NOTIFY_URI_V2):
 headers = {'Authorization': ('Bearer %s' % token), 'Content-Type': 'application/json'}
 body = dict()
 body['message'] = msg
 body['color'] = color
 body['message_format'] = msg_format
 body['notify'] = notify
 POST_URL = (api + NOTIFY_URI_V2)
 url = POST_URL.replace('{id_or_name}', urllib.pathname2url(room))
 data = json.dumps(body)
 if module.check_mode:
  module.exit_json(changed=False)
 (response, info) = fetch_url(module, url, data=data, headers=headers, method='POST')
 if (info['status'] in [200, 204]):
  return response.read()
 else:
  module.fail_json(msg=('failed to send message, return status=%s' % str(info['status'])))

def send_msg_v2 ( module , token , room , msg_from , msg , msg_format = 'text' , color = 'yellow' , notify = False , api = NOTIFY_URI_V2 ) : headers = { 'Authorization' : ( 'Bearer %s' % token ) , 'Content-Type' : 'application/json' } body = dict ( ) body [ 'message' ] = msg body [ 'color' ] = color body [ 'message_format' ] = msg_format body [ 'notify' ] = notify POST_URL = ( api + NOTIFY_URI_V2 ) url = POST_URL . replace ( '{id_or_name}' , urllib . pathname2url ( room ) ) data = json . dumps ( body ) if module . check_mode : module . exit_json ( changed = False ) ( response , info ) = fetch_url ( module , url , data = data , headers = headers , method = 'POST' ) if ( info [ 'status' ] in [ 200 , 204 ] ) : return response . read ( ) else : module . fail_json ( msg = ( 'failed to send message, return status=%s' % str ( info [ 'status' ] ) ) )
sending message to hipchat v2 server .