serverdensity/chef-serverdensity — pull request #5 by mal (2013-12-08 15:51:56+00:00)
Title: LWRP Refactor

The `README` changes should tell you all you need to know, so this is going to focus on what you don't need to know, but might be useful.

- Using a custom partial API (v1, v2) found in `libraries/`
Ideally this would be replaced with a dedicated API gem, but I couldn't find one that met the needs of this cookbook.
- Supports non-LWRP based usage, but does introduce breaking changes; suggest version bump to `2.0.0`
- The alert LWRP sort of cheats and leaves it to the user to sort out v1/v2 differences in alert creation, ideally this would be abstracted away, but time/effort etc
- `agent_key` is cached in the node's data, override it to `nil` to force a new read from the API
- intended usage is to remove all alerts, and then reapply them because tracking alerts is impractical, this provides two benefits;
1. old alerts get removed
2. alerts do not get duplicated
- `:update` and `:clear` are separate actions, so that it's possible to configure the agent without wiping existing alerts

Here's an example of v1 usage:
```rb
include_recipe 'serverdensity'

# unless `device` is passed here (see README), the name is used to lookup the node by name,
# for devices created this way, it's more reliable than hostname
serverdensity node.name do
account 'idio.serverdensity.com'
username "chef"
password ""
# dual action, update the device, and clear all alerts (without clear, alerts rapidly start to
# duplicate as there's no easy way to track them)
action [:update, :clear]
end

serverdensity_alert 'high-load' do
# metadata gets sent straight to the API, errors are logged as Chef warnings so as not to
# interrupt an otherwise successful run
metadata(
:userId => ['group'],
:notificationType => ['email'],
:checkType => 'loadAvrg',
:comparison => :>,
:triggerThreshold => 3
)
end
```

and v2:
```rb
include_recipe 'serverdensity'

serverdensity node.name do
account 'idio.serverdensity.com'
token "000000000000000000000000000000"
action [:update, :clear]
end

...
```

Happy to answer any questions you may have, cheers!