summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPerry A. Stoll <perry@pstoll.com>2013-07-26 10:22:24 -0400
committerPerry A. Stoll <perry@pstoll.com>2013-07-26 10:22:24 -0400
commit5a07efde89d37d400e9de274e949d6ae6e350e06 (patch)
tree08c76a120eb986b4ea9b979e039544c2b1efcb1d
parentf4bbfe56cc547be036f9ca2db134c0117a51b13c (diff)
downloadcouchdb-5a07efde89d37d400e9de274e949d6ae6e350e06.tar.gz
refactor alert sending functions
-rw-r--r--src/custodian/src/custodian_server.erl53
1 files changed, 22 insertions, 31 deletions
diff --git a/src/custodian/src/custodian_server.erl b/src/custodian/src/custodian_server.erl
index 6dcf509fb..ea92fb9ce 100644
--- a/src/custodian/src/custodian_server.erl
+++ b/src/custodian/src/custodian_server.erl
@@ -112,34 +112,25 @@ check_shards() ->
send_one_copy_alert(OneCopy),
send_impaired_alert(Impaired).
-send_conflicted_alert(0) ->
- twig:log(notice, "No partition tables conflicted in this cluster", []),
- os:cmd("send_snmptrap --trap CLOUDANT-DBCORE-MIB::cloudantDbcoreNoPartitionTablesConflictedEvent");
-send_conflicted_alert(Count) when is_integer(Count) ->
- twig:log(crit, "~B conflicted partition tables in this cluster", [Count]),
- os:cmd("send_snmptrap --trap CLOUDANT-DBCORE-MIB::cloudantDbcorePartitionTablesConflictedEvent -o cloudantDbcoreShardCount:INTEGER:"
- ++ integer_to_list(Count)).
-
-send_impaired_alert(0) ->
- twig:log(notice, "No shards impaired in this cluster", []),
- os:cmd("send_snmptrap --trap CLOUDANT-DBCORE-MIB::cloudantDbcoreAllShardsUnimpairedEvent");
-send_impaired_alert(Count) when is_integer(Count) ->
- twig:log(crit, "~B impaired shards in this cluster", [Count]),
- os:cmd("send_snmptrap --trap CLOUDANT-DBCORE-MIB::cloudantDbcoreShardsImpairedEvent -o cloudantDbcoreShardCount:INTEGER:"
- ++ integer_to_list(Count)).
-
-send_unavailable_alert(0) ->
- twig:log(notice, "All shards are available in this cluster", []),
- os:cmd("send_snmptrap --trap CLOUDANT-DBCORE-MIB::cloudantDbcoreAllShardsAvailableEvent");
-send_unavailable_alert(Count) when is_integer(Count) ->
- twig:log(crit, "~B unavailable shards in this cluster", [Count]),
- os:cmd("send_snmptrap --trap CLOUDANT-DBCORE-MIB::cloudantDbcoreShardsUnavailableEvent -o cloudantDbcoreShardCount:INTEGER:"
- ++ integer_to_list(Count)).
-
-send_one_copy_alert(0) ->
- twig:log(notice, "No shards with only one copy in this cluster", []),
- os:cmd("send_snmptrap --trap CLOUDANT-DBCORE-MIB::cloudantDbcoreAllShardsMultipleCopiesEvent");
-send_one_copy_alert(Count) when is_integer(Count) ->
- twig:log(crit, "~B shards with only one copy in this cluster", [Count]),
- os:cmd("send_snmptrap --trap CLOUDANT-DBCORE-MIB::cloudantDbcoreShardsOneCopyEvent -o cloudantDbcoreShardCount:INTEGER:"
- ++ integer_to_list(Count)).
+%% specific alert functions
+send_conflicted_alert(Count) ->
+ send_snmp_alert(Count, "partition tables conflicted", "NoPartitionTablesConflictedEvent", "PartitionTablesConflictedEvent").
+
+send_impaired_alert(Count) ->
+ send_snmp_alert(Count, "shards impaired", "AllShardsUnimpairedEvent", "ShardsImpairedEvent").
+
+send_unavailable_alert(Count) ->
+ send_snmp_alert(Count, "unavailable shards", "AllShardsAvailableEvent", "ShardsUnavailableEvent").
+
+send_one_copy_alert(Count) ->
+ send_snmp_alert(Count, "shards with only one copy", "AllShardsMultipleCopiesEvent", "ShardsOneCopyEvent").
+
+%% generic SNMP alert functions
+send_snmp_alert(0, AlertType, ClearMib, _) ->
+ twig:log(notice, "No ~s in this cluster", [AlertType]),
+ Cmd = lists:concat(["send_snmptrap --trap CLOUDANT-DBCORE-MIB::cloudantDbcore", ClearMib]),
+ os:cmd(Cmd);
+send_snmp_alert(Count, AlertType, _, AlertMib) when is_integer(Count) ->
+ twig:log(crit, "~B ~s in this cluster", [Count, AlertType]),
+ Cmd = lists:concat(["send_snmptrap --trap CLOUDANT-DBCORE-MIB::cloudantDbcore", AlertMib," -o cloudantDbcoreShardCount:INTEGER ", Count]),
+ os:cmd(Cmd).