sensu / sensu-dashboard

A dashboard for Sensu, for displaying & managing events & clients.
http://sensuapp.org
MIT License
96 stars 44 forks source link

Client list view with links to external graphs #133

Open shaftoe opened 11 years ago

shaftoe commented 11 years ago

We're happily using sensu-dashboard and so far one missing key feature for us (and relatively easy to implement I guess) is a way to easily browse graphs related to a single machine. For instance we keep statistical data on hostedgraphite.com, so if we want to look at data for server1, we have to open the browser and type something like:

https://www.hostedgraphite.com/xxxxxxxx/graphite/dashboard/#server1

(actually we have a shortened url redirect to make it easier but still suboptimal).

My first idea was to write a simple PHP script to generate links reading client list from sensu /clients api, but then my colleague suggested me this could be something of interest for other sensu users (for sure we're not the only one storing data on Graphite!) so, before digging into the code to see if it's not to hard, I'm here asking for suggestions.

How do you deal with this (minor) problem? Would it be hard/overkill to write some kind of plugin for sensu-dashboard to have custom links in #cilents view? perhaps a new column with a 'open graphs' link?

PS For us the URL is always predictable, with just the ending part to be replaced with the client name, so one single parameter in the config should suffice.

stormtrooperguy commented 11 years ago

I just came here looking for the same thing. This would be an AWESOME feature to add. I'm looking at how to make the change myself right now, but this is the first time I've looked at the dashboard code. Any pointers? :)

stormtrooperguy commented 11 years ago

shaftoe - I need to do something today to make the dahsboard links work on my install of sensu. Here's what I did:

For my environment the graph URL could be different depending on the system being monitored, so I wanted it to be defined on the client site in the config.

Step 1: Added "graphurl" to my client.json on the nodes:

{ "client": { "name": "node", "address": "node.domain.com", "subscriptions": [], "graphurl": "http://host.domain.com/overview.php?host=node" } }

Step 2: Edited list.coffee to tell it to pick up the graphurl if present: (/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-dashboard-0.9.9/lib/sensu-dashboardassets/javascripts/views/clients/list.coffee)

After: result || _.detect(record.get("subscriptions"), (sub) => liquidMetal.score(sub, token.object) > 0.96) != undefined

Add: result || _.detect(record.get("graphurl"), (sub) => liquidMetal.score(sub, token.object) > 0.96) != undefined

Step 3: Edited list.hbs to add a column header to the client view for dashboard:

After:

{{timestamp}}

Add:

{{name}}

Step 4: Edited list_item.hbs to add the graph url

After:

       <td class="timestamp">{{timestamp}}</td>

Add:

       <td class="dashboard"><a href="{{graphurl}}" target=_new>{{name}}</a></td>

This seems to be doing the trick for me. It's an awkward hack that will be tough to maintain, but since adoption of Sensu for us depends on having this, it was worth it.

If this seems like a good approach to the Sensu team, I'd be happy to work on forking the code / making the changes in some way to get merged in.

shaftoe commented 11 years ago

@stormtrooperguy this issue is not so blocking for us so we haven't found a solution yet, but thanks a lot for the how-to, when (if) I'll implement it for us I'll remember you saved me a lot of time digging into the code!

portertech commented 11 years ago

I'd prefer to see the dashboard detect URLs in attribute values, transforming them into hrefs. This would work for Graphite dashboard URLs and "playbooks".

stormtrooperguy commented 11 years ago

Agreed... I just didn't have time to dig in to figure out where those values were calculated :) If someone can point me at the right place I can go back and do it that way.

amdprophet commented 11 years ago

I would probably create a new handlebars helper that uses regex to determine whether or not a string contains a URL

https://github.com/sensu/sensu-dashboard/blob/master/lib/sensu-dashboard/assets/javascripts/handlebars_helpers.coffee http://stackoverflow.com/questions/1500260/detect-urls-in-text-with-javascript