#! /usr/bin/env python
#
# Copyright (c) 2016 johnny-die-tulpe
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import datetime, socket
from sauron import logger
from sauron.emitters import Emitter, EmitterException
from influxdb import InfluxDBClient

class InfluxDbPush(Emitter):
  def __init__(self, host, port, user, password, dbname='illuminati', **kwargs):
    Emitter.__init__(self)
    self.myname = socket.getfqdn()
    self.client = InfluxDBClient(host, port, usernaem, password, dbname)
    self.client.create_database(dbname)
    self.client.switch_database(dbname)

  def metrics(self, metrics):
    payload = []
    for name, results in metrics.items():
      for key,value in results['results'].items():
        v, u = value
        datapoint = { "measurement": "%s-%s" % (name, key),
                      "tags": { "host": self.myname, "unit": u },
                      "time": int(datetime.datetime.now().strftime('%s')),
                      "fields": { "value": v }
        }
        logger.info('To InfluxDB %s-%s => %s' % (name, key, repr(value)))
        payload.append(datapoint)
    self.client.write_points(payload)

@@ -1255,16 +1255,68 @@
 DBClient
+%0Afrom influxdb.exceptions import InfluxDBClientError
 %0A%0Aclass 
@@ -1534,12 +1534,8 @@
 user
-naem
 , pa
@@ -1542,32 +1542,43 @@
 ssword, dbname)%0A
+    try:%0A  
     self.client.
@@ -1597,24 +1597,67 @@
 ase(dbname)%0A
+    except InfluxDBClientError:%0A      pass%0A
     self.cli

fix typo