Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import sys
  4. from optparse import OptionParser
  5. import ConfigParser
  6. from influxdb import InfluxDBClient
  7.  
  8. G_VALID_STATUS = ['start', 'stop']
  9.  
  10.  
  11. def annotate(filename, status, configp):
  12.  
  13. # Load Influxdb Configuration
  14. _host = configp.get('influxdb', 'host')
  15. _port = configp.getint('influxdb', 'port')
  16. _user = configp.get('influxdb', 'user')
  17. _pass = configp.get('influxdb', 'pass')
  18. _dbname = configp.get('influxdb', 'dbname')
  19.  
  20. annotation_body = [
  21. {
  22. "measurement": "events",
  23. "tags": {
  24. "type": "pcap",
  25. "status": "start".format(status),
  26. "text": "Playback of {}".format(filename)
  27. },
  28. "fields": {
  29. "file": "{}".format(filename)
  30. }
  31. }
  32. ]
  33.  
  34. client = InfluxDBClient(_host, _port, _user, _pass, _dbname)
  35.  
  36. try:
  37. client.create_database(_dbname)
  38. except:
  39. pass
  40.  
  41. client.switch_database(_dbname)
  42. client.switch_user(_user, _pass)
  43.  
  44. client.write_points(annotation_body)
  45.  
  46.  
  47. if __name__ == '__main__':
  48. parser = OptionParser()
  49. parser.add_option('--config', dest='config', help='Configuration')
  50. parser.add_option('--file', dest='file', help='Filename to annotate the Influxdb replay_events database')
  51. parser.add_option('--status', dest='status', help="Status of event - start or stop")
  52. (options, args) = parser.parse_args()
  53.  
  54. if len(sys.argv) == 1 or len(options.config) == 0:
  55. parser.print_help()
  56. sys.exit(1)
  57.  
  58. configp = ConfigParser.ConfigParser()
  59. configp.read(options.config)
  60.  
  61. if options.status not in G_VALID_STATUS:
  62. print '{} is not a valid status - {}'.format(options.status, G_VALID_STATUS)
  63. sys.exit(1)
  64.  
  65. annotate(options.file, options.status, configp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement