Advertisement
Guest User

Untitled

a guest
Jul 12th, 2016
112
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #---Creating measurement---------------------
  2.  
  3. ping = Ping(
  4.     af=4,
  5.     target="89.185.136.254",
  6.     description="test",
  7.     packets=1,
  8.     interval=60)
  9.  
  10. source = AtlasSource(type="probes", value='16233', requested=1)
  11.  
  12. atlas_request = AtlasCreateRequest(
  13.     start_time=datetime.utcnow(),
  14.     key=ATLAS_API_KEY,
  15.     measurements=[ping],
  16.     sources=[source],
  17.     is_oneoff=True
  18. )
  19.  
  20. (is_success, response) = atlas_request.create()
  21.  
  22. print(is_success)
  23. print(response)
  24. mdata = Measurement(id=response['measurements'])
  25. print(mdata)
  26. print(mdata.status) #This prints 'None'
  27.  
  28. #-----------------------------------------------------------------
  29. #--Getting results--------------------
  30.  
  31. def on_result_response(*args):
  32.     """
  33.     Function that will be called every time we receive a new result.
  34.     Args is a tuple, so you should use args[0] to access the real message.
  35.     """
  36.     print(args)
  37.     measurm = Measurement(id=args[0]['msm_id'])
  38.     print(measurm)
  39.     print(measurm.status)
  40.     print(dir(measurm))
  41.  
  42. atlas_stream = AtlasStream()
  43. atlas_stream.connect()
  44.  
  45. channel = "result"
  46. # Bind function we want to run with every result message received
  47. atlas_stream.bind_channel(channel, on_result_response)
  48.  
  49. # Subscribe to new stream for measurement results
  50. stream_parameters = {"msm": response['measurements']}
  51. print(datetime.utcnow())
  52. atlas_stream.start_stream(stream_type="result", **stream_parameters)
  53.  
  54. # Timeout all subscriptions after 5 secs. Leave seconds empty for no timeout.
  55. # Make sure you have this line after you start *all* your streams
  56. atlas_stream.timeout(seconds=240)
  57. print(datetime.utcnow())
  58. # Shut down everything
  59. atlas_stream.disconnect()
Advertisement
RAW Paste Data Copied
Advertisement