The default behavior is to create one measurement per alert.event in InfluxDB. Several processes are easier if all Alerta data is available in a single measurement with a tag that indicates alert.event.
This introduces two new config variables:
INFLUXDB_SEPARATE_MEASUREMENT defaults to True and triggers the default (separate measurement per event) behavior.
INFLUXDB_SINGLE_MEASUREMENT defaults to False and triggers the new behavior of one measurement for all events. If set it should be set to the name of the measurement you want to use (e.g. not True but rather "alert_measurement").
Both settings can be either True or False (i.e. it isn't one or the other behavior...you can have both). The InfluxDB points now start as an empty list (line 46). If either of the above config variables are True a point is added to the list in the format appropriate for that setting. In the case of INFLUXDB_SEPARATE_MEASUREMENT (default behavior) this is unchanged. In the case of INFLUXDB_SINGLE_MEASUREMENT (new behavior) this point uses the value set in INFLUXDB_SINGLE_MEASUREMENT as a measurement name and adds a new tag called "event" which is populated with the alert.event value.
I've made one other change to each point type which is to coerce the value field (alert.value in both cases) to a string. The issue we ran into is that InfluxDB defines a field's type based on the first point. If the first point is a string the old code worked fine (numbers were treated as strings), but if the first point was numeric InfluxDB would drop subsequent points that included string values. Since Alerta allows string values (and has to it would seem) I've forced this field to be a string in InfluxDB.
Finally within the final try block to write points to InfluxDB I changed this to only do so if the points list is not empty. This handles the case where both configuration variables are false and nothing is written.