How can I use a trigger to match database errors with the IPs that saw them?

triggers

#1

This is done with what we have called a “key overload”, and the trigger is quite simple:

DB_RESPONSE - the error comes on the database response

We only want to run this if there is an error:

if (DB.error != null) { 

Grab the error and the client IP address

     var error = DB.error;
     var clientAddress = Flow.client.ipaddr;

Combine (or overload) the error and client address into a single variable

     var errorandaddress = clientAddress + " : " + error;

Stick the variable into a detail counter for viewing.

     Device.metricAddCount("db_error_count", 1);                                 
     Device.metricAddDetailCount("db_error_count_detail", errorandaddress, 1);
}

Notice how the key is overloaded with both the error and client IP address.

More examples of this to follow!