PagerDuty integration
I recently did this for Cisco on one of their newer projects. In case you were curious, this is likely only a couple of hours of developer time. Easy peasy.
One other thought, the way I implemented it was as a Nagios handler. Nagios lets you execute an arbitrary command, specifying what arguments get passed to it in Argv. I was able to easily take this and do an HTTP request to the PagerDuty API. In the event handler I wrote, I also had it updating a Stashboard instance in certain conditions.
Maybe it would be useful to have something open-ended like this so that alternate alerting platforms could be used, or who knows what other uses people will come up with for alerts.
@ryanuber This was kind of a "thought" ticket for me. Any integration with Consul would just use it's existing APIs (specifically the various /v1/health/ endpoints). I don't think PagerDuty would be "blessed" in any way. Just some generic set of wrappers around the existing HTTP API.
Would it be useful to implement this as a type of webhook? That way status changes could fire off to a 3rd party application that could then do whatever it wants, including sending to pagerduty?
@armon there are a couple of ways to integrate with PagerDuty. lots of people integrate with us via PD Connect: https://www.pagerduty.com/docs/integration-api/pagerduty-connect/ if you need help with the integration, feel free to reach out to me at [email protected]
My company doesn't use PagerDuty, but I definitely would love to have something where an arbitrary shellscript or command is executed when the state changes on an item. My use case is to get a webhook called for VictorOps alerting. I'd be happy to take a crack at implementing it if someone could point me toward where the Consul Servers register the health state change.
So yeah, I dug into the code and I see why this is difficult. You set the state on the client side, and then just sync the data to the servers, and the server doesn't really know or care what has changed, it just syncs the registered check up to its state storage.
If I'm reading this right, that means the hook would have to originate from fsm.go around the call to EnsureCheck.
That also means that as it gets synced between servers, EnsureCheck gets called on every single one, which would lead to duplicate calls to whatever hook that was created.
It feels like this could work but it would need a proxy to de-duplicate the calls, or just have another server poll Consul check states every few seconds (how likely is this to tip over a Consul cluster?) and keep its own idempotent list, as ugly as that would be, using that to call appropriate alerting mechanisms.
I could also just have the agents themselves call an internal webhook from the check script too, I guess.
My feeling is it is best to use the blocking queries from the outside of Consul to watch for changes, as opposed to anything invasive in the FSM / state store itself.
Yeah, I agree. The term "blocking query" confused me a bit initially, since when I read "blocking" I initially thought it meant block as in a consistent query - nothing could be written until the query finished. Long polling of the health endpoints basically is what I need, though it sounds like I would need to detect state changes by myself since a return doesn't guarantee a change in state. That's easy enough to do though.
I am inclined to agree, I was surprised to see that Consul could replace nagios in some ways, but the actual alerting component seems missing, but it seems like that should exist as another entity altogether that periodically queries consul.
Then it would be good to have alerts on a per-cluster basis, e.g. Fire off a page if 2/5 db cluster nodes are out, but if only one is out, just send an email.
It seems odd to put direct PagerDuty integration into Consul core. This strikes me as a better side project along the lines of consul-haproxy or such. And agreed that this slots right in with blocking queries.
Yeah, I'm planning on writing something and I'll open source it when I do.
On Mon, Aug 25, 2014 at 9:24 AM, Carl Johnson [email protected] wrote:
It seems odd to integrate direct PagerDuty integration into Consul core. This strikes me as a better side project along the lines of consul-haproxy or such. And agreed that this slots right in with blocking queries.
— Reply to this email directly or view it on GitHub https://github.com/hashicorp/consul/issues/13#issuecomment-53287372.
I'd love for Consul to have some sort of webhook-esque alerting mechanism.
@davedash has the right idea. An agent that lives along side consul and handles dealing with warning and critical checks/services and then performs an arbitrary action (call pagerduty, send email, write to redis) would be what would meet my needs. You could even make these agents services in consul so they'd be more fault tolerant. I'm thinking about building something simple that would have this functionality but to be a fully fledged nagios replacement, it would need to support some additional features like notification periods per health check, custom actions per health check (think: only email for this check, no pagerduty), and optionally parenting. I have some ideas about how to implement these but it would involve adding additional data to each health check's configuration.
Seems like this is solvable with the current watch mechanism. The issue is defining what circumstances may deserve a pagerduty event trigger. Losing a node? Losing a service?
Of course when I've got a cluster of > 32 nodes, I don't want to be woken up at 3am just because I lose one. So I feel like you probably want CEP so you can rollup, alert based on percent of nodes down, &c. None of this should be inside consul. I'd prefer to push the watch event stream to logstash, riemann or heka, and send the alert notification from that side.
@josephholsten Agreed that the integration itself doesn't belong on Consul proper. What's the watch mechanism though? Thus far I haven't found anything better than periodic polling.
Look at blocking queries in the HTTP API. It's a long poll style thing that returns on timeout or state change.
-----Original Message----- From: "Morgante Pell" [email protected] Sent: 8/29/2014 12:55 PM To: "hashicorp/consul" [email protected] Cc: "highlyunavailable" [email protected] Subject: Re: [consul] PagerDuty integration (#13)
@josephholsten Agreed that the integration itself doesn't belong on Consul proper. What's the watch mechanism though? Thus far I haven't found anything better than periodic polling. — Reply to this email directly or view it on GitHub.
@armon Now that the consul watch handler mechanism is present in 0.4.0 should this be closed out?
@jrnt30 I'd like to maybe have some handler that can be used with consul watch to do this. I never intended the PD integration to be in Consul core.
I think that's what @jrnt30 was saying - this is exactly the mechanism we need to call a script to send an alert through an alerting system, so this bug is "closed" pending minor customization by the user.
Fiar enough. Closing.