metadata.yaml 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # yamllint disable rule:line-length
  2. ---
  3. - id: 'notify-custom'
  4. meta:
  5. name: 'Custom'
  6. link: ''
  7. categories:
  8. - notify.agent
  9. icon_filename: 'custom.png'
  10. keywords:
  11. - custom
  12. overview:
  13. notification_description: |
  14. Netdata Agent's alert notification feature allows you to send custom notifications to any endpoint you choose.
  15. notification_limitations: ''
  16. setup:
  17. prerequisites:
  18. list:
  19. - title: ''
  20. description: |
  21. - Access to the terminal where Netdata Agent is running
  22. configuration:
  23. file:
  24. name: 'health_alarm_notify.conf'
  25. options:
  26. description: 'The following options can be defined for this notification'
  27. folding:
  28. title: 'Config Options'
  29. enabled: true
  30. list:
  31. - name: 'SEND_CUSTOM'
  32. default_value: 'YES'
  33. description: "Set `SEND_CUSTOM` to YES"
  34. required: true
  35. - name: 'DEFAULT_RECIPIENT_CUSTOM'
  36. default_value: ''
  37. description: "This value is dependent on how you handle the `${to}` variable inside the `custom_sender()` function."
  38. required: true
  39. detailed_description: |
  40. All roles will default to this variable if left unconfigured. You can edit `DEFAULT_RECIPIENT_CUSTOM` with the variable you want, in the following entries at the bottom of the same file:
  41. ```
  42. role_recipients_custom[sysadmin]="systems"
  43. role_recipients_custom[domainadmin]="domains"
  44. role_recipients_custom[dba]="databases systems"
  45. role_recipients_custom[webmaster]="marketing development"
  46. role_recipients_custom[proxyadmin]="proxy-admin"
  47. role_recipients_custom[sitemgr]="sites"
  48. ```
  49. - name: 'custom_sender()'
  50. default_value: ''
  51. description: "You can look at the other senders in `/usr/libexec/netdata/plugins.d/alarm-notify.sh` for examples of how to modify the function in this configuration file."
  52. required: false
  53. detailed_description: |
  54. The following is a sample custom_sender() function in health_alarm_notify.conf, to send an SMS via an imaginary HTTPS endpoint to the SMS gateway:
  55. ```
  56. custom_sender() {
  57. # example human readable SMS
  58. local msg="${host} ${status_message}: ${alarm} ${raised_for}"
  59. # limit it to 160 characters and encode it for use in a URL
  60. urlencode "${msg:0:160}" >/dev/null; msg="${REPLY}"
  61. # a space separated list of the recipients to send alarms to
  62. to="${1}"
  63. for phone in ${to}; do
  64. httpcode=$(docurl -X POST \
  65. --data-urlencode "From=XXX" \
  66. --data-urlencode "To=${phone}" \
  67. --data-urlencode "Body=${msg}" \
  68. -u "${accountsid}:${accounttoken}" \
  69. https://domain.website.com/)
  70. if [ "${httpcode}" = "200" ]; then
  71. info "sent custom notification ${msg} to ${phone}"
  72. sent=$((sent + 1))
  73. else
  74. error "failed to send custom notification ${msg} to ${phone} with HTTP error code ${httpcode}."
  75. fi
  76. done
  77. }
  78. ```
  79. The supported variables that you can use for the function's `msg` variable are:
  80. | Variable name | Description |
  81. |:---------------------------:|:---------------------------------------------------------------------------------|
  82. | `${alarm}` | Like "name = value units" |
  83. | `${status_message}` | Like "needs attention", "recovered", "is critical" |
  84. | `${severity}` | Like "Escalated to CRITICAL", "Recovered from WARNING" |
  85. | `${raised_for}` | Like "(alarm was raised for 10 minutes)" |
  86. | `${host}` | The host generated this event |
  87. | `${url_host}` | Same as ${host} but URL encoded |
  88. | `${unique_id}` | The unique id of this event |
  89. | `${alarm_id}` | The unique id of the alarm that generated this event |
  90. | `${event_id}` | The incremental id of the event, for this alarm id |
  91. | `${when}` | The timestamp this event occurred |
  92. | `${name}` | The name of the alarm, as given in netdata health.d entries |
  93. | `${url_name}` | Same as ${name} but URL encoded |
  94. | `${chart}` | The name of the chart (type.id) |
  95. | `${url_chart}` | Same as ${chart} but URL encoded |
  96. | `${status}` | The current status : REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL |
  97. | `${old_status}` | The previous status: REMOVED, UNINITIALIZED, UNDEFINED, CLEAR, WARNING, CRITICAL |
  98. | `${value}` | The current value of the alarm |
  99. | `${old_value}` | The previous value of the alarm |
  100. | `${src}` | The line number and file the alarm has been configured |
  101. | `${duration}` | The duration in seconds of the previous alarm state |
  102. | `${duration_txt}` | Same as ${duration} for humans |
  103. | `${non_clear_duration}` | The total duration in seconds this is/was non-clear |
  104. | `${non_clear_duration_txt}` | Same as ${non_clear_duration} for humans |
  105. | `${units}` | The units of the value |
  106. | `${info}` | A short description of the alarm |
  107. | `${value_string}` | Friendly value (with units) |
  108. | `${old_value_string}` | Friendly old value (with units) |
  109. | `${image}` | The URL of an image to represent the status of the alarm |
  110. | `${color}` | A color in AABBCC format for the alarm |
  111. | `${goto_url}` | The URL the user can click to see the netdata dashboard |
  112. | `${calc_expression}` | The expression evaluated to provide the value for the alarm |
  113. | `${calc_param_values}` | The value of the variables in the evaluated expression |
  114. | `${total_warnings}` | The total number of alarms in WARNING state on the host |
  115. | `${total_critical}` | The total number of alarms in CRITICAL state on the host |
  116. examples:
  117. folding:
  118. enabled: true
  119. title: ''
  120. list:
  121. - name: 'Basic Configuration'
  122. folding:
  123. enabled: false
  124. description: ''
  125. config: |
  126. #------------------------------------------------------------------------------
  127. # custom notifications
  128. SEND_CUSTOM="YES"
  129. DEFAULT_RECIPIENT_CUSTOM=""
  130. # The custom_sender() is a custom function to do whatever you need to do
  131. custom_sender() {
  132. # example human readable SMS
  133. local msg="${host} ${status_message}: ${alarm} ${raised_for}"
  134. # limit it to 160 characters and encode it for use in a URL
  135. urlencode "${msg:0:160}" >/dev/null; msg="${REPLY}"
  136. # a space separated list of the recipients to send alarms to
  137. to="${1}"
  138. for phone in ${to}; do
  139. httpcode=$(docurl -X POST \
  140. --data-urlencode "From=XXX" \
  141. --data-urlencode "To=${phone}" \
  142. --data-urlencode "Body=${msg}" \
  143. -u "${accountsid}:${accounttoken}" \
  144. https://domain.website.com/)
  145. if [ "${httpcode}" = "200" ]; then
  146. info "sent custom notification ${msg} to ${phone}"
  147. sent=$((sent + 1))
  148. else
  149. error "failed to send custom notification ${msg} to ${phone} with HTTP error code ${httpcode}."
  150. fi
  151. done
  152. }
  153. troubleshooting:
  154. problems:
  155. list: []