Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import sys
- from optparse import OptionParser
- import ConfigParser
- from influxdb import InfluxDBClient
- G_VALID_STATUS = ['start', 'stop']
- def annotate(filename, status, configp):
- # Load Influxdb Configuration
- _host = configp.get('influxdb', 'host')
- _port = configp.getint('influxdb', 'port')
- _user = configp.get('influxdb', 'user')
- _pass = configp.get('influxdb', 'pass')
- _dbname = configp.get('influxdb', 'dbname')
- annotation_body = [
- {
- "measurement": "events",
- "tags": {
- "type": "pcap",
- "status": "start".format(status),
- "text": "Playback of {}".format(filename)
- },
- "fields": {
- "file": "{}".format(filename)
- }
- }
- ]
- client = InfluxDBClient(_host, _port, _user, _pass, _dbname)
- try:
- client.create_database(_dbname)
- except:
- pass
- client.switch_database(_dbname)
- client.switch_user(_user, _pass)
- client.write_points(annotation_body)
- if __name__ == '__main__':
- parser = OptionParser()
- parser.add_option('--config', dest='config', help='Configuration')
- parser.add_option('--file', dest='file', help='Filename to annotate the Influxdb replay_events database')
- parser.add_option('--status', dest='status', help="Status of event - start or stop")
- (options, args) = parser.parse_args()
- if len(sys.argv) == 1 or len(options.config) == 0:
- parser.print_help()
- sys.exit(1)
- configp = ConfigParser.ConfigParser()
- configp.read(options.config)
- if options.status not in G_VALID_STATUS:
- print '{} is not a valid status - {}'.format(options.status, G_VALID_STATUS)
- sys.exit(1)
- annotate(options.file, options.status, configp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement