Skip to content

Commit

Permalink
add plugin notify_telegram for collectd 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
YanikusGG committed May 11, 2024
1 parent 3ce45a7 commit eb98405
Show file tree
Hide file tree
Showing 6 changed files with 950 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,15 @@ notify_nagios_la_SOURCES = src/notify_nagios.c
notify_nagios_la_LDFLAGS = $(PLUGIN_LDFLAGS)
endif

if BUILD_PLUGIN_NOTIFY_TELEGRAM
pkglib_LTLIBRARIES += notify_telegram.la
notify_telegram_la_SOURCES = src/notify_telegram.c
notify_telegram_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBCURL_CFLAGS)
notify_telegram_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBYAJL_CPPFLAGS) $(BUILD_WITH_LIBMICROHTTPD_CPPFLAGS)
notify_telegram_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBYAJL_LDFLAGS) $(BUILD_WITH_LIBMICROHTTPD_LDFLAGS)
notify_telegram_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS) $(BUILD_WITH_LIBYAJL_LIBS) $(BUILD_WITH_LIBMICROHTTPD_LIBS)
endif

if BUILD_PLUGIN_NTPD
pkglib_LTLIBRARIES += ntpd.la
ntpd_la_SOURCES = src/ntpd.c
Expand Down
4 changes: 4 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,10 @@ Features
- notify_nagios
Submit notifications as passive check results to a local nagios instance.

- notify_telegram
Send telegram message with the notification to the configured
recipients.

- exec
Execute a program or script to handle the notification.
See collectd-exec(5).
Expand Down
7 changes: 7 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -6839,6 +6839,7 @@ plugin_nginx="$with_libcurl"
plugin_notify_desktop="$with_libnotify"
plugin_notify_email="$with_libesmtp"
plugin_notify_nagios="yes"
plugin_notify_telegram="no"
plugin_ntpd="yes"
plugin_numa="no"
plugin_nut="$with_libupsclient"
Expand Down Expand Up @@ -7095,6 +7096,10 @@ if test "x$with_libcurl" = "xyes" && test "x$with_libxml2" = "xyes"; then
fi
fi
if test "x$with_libcurl" = "xyes" && test "x$with_libssl" = "xyes" && test "x$with_libyajl" = "xyes" && test "x$with_libyajl2" = "xyes" && test "x$with_libmicrohttpd" = "xyes"; then
plugin_notify_telegram="yes"
fi
if test "x$with_libcurl" != "xyes"; then
plugin_write_http="no (libcurl not found)"
plugin_bind="no (libcurl not found)"
Expand Down Expand Up @@ -7544,6 +7549,7 @@ AC_PLUGIN([nginx], [$plugin_nginx], [nginx statistics]
AC_PLUGIN([notify_desktop], [$plugin_notify_desktop], [Desktop notifications])
AC_PLUGIN([notify_email], [$plugin_notify_email], [Email notifier])
AC_PLUGIN([notify_nagios], [$plugin_notify_nagios], [Nagios notification plugin])
AC_PLUGIN([notify_telegram], [$plugin_notify_telegram], [Telegram notifier])
AC_PLUGIN([ntpd], [$plugin_ntpd], [NTPd statistics])
AC_PLUGIN([numa], [$plugin_numa], [NUMA virtual memory statistics])
AC_PLUGIN([nut], [$plugin_nut], [Network UPS tools statistics])
Expand Down Expand Up @@ -7992,6 +7998,7 @@ AC_MSG_RESULT([ nginx . . . . . . . . $enable_nginx])
AC_MSG_RESULT([ notify_desktop . . . $enable_notify_desktop])
AC_MSG_RESULT([ notify_email . . . . $enable_notify_email])
AC_MSG_RESULT([ notify_nagios . . . . $enable_notify_nagios])
AC_MSG_RESULT([ notify_telegram . . . $enable_notify_telegram])
AC_MSG_RESULT([ ntpd . . . . . . . . $enable_ntpd])
AC_MSG_RESULT([ numa . . . . . . . . $enable_numa])
AC_MSG_RESULT([ nut . . . . . . . . . $enable_nut])
Expand Down
14 changes: 14 additions & 0 deletions src/collectd.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
#@BUILD_PLUGIN_NOTIFY_DESKTOP_TRUE@LoadPlugin notify_desktop
#@BUILD_PLUGIN_NOTIFY_EMAIL_TRUE@LoadPlugin notify_email
#@BUILD_PLUGIN_NOTIFY_NAGIOS_TRUE@LoadPlugin notify_nagios
#@BUILD_PLUGIN_NOTIFY_TELEGRAM_TRUE@LoadPlugin notify_telegram
#@BUILD_PLUGIN_NTPD_TRUE@LoadPlugin ntpd
#@BUILD_PLUGIN_NUMA_TRUE@LoadPlugin numa
#@BUILD_PLUGIN_NUT_TRUE@LoadPlugin nut
Expand Down Expand Up @@ -1283,6 +1284,19 @@
# CommandFile "/usr/local/nagios/var/rw/nagios.cmd"
#</Plugin>

#<Plugin notify_telegram>
# BotToken "telegram-bot-token"
# ProxyURL "https://api.telegram.org/bot"
# DisableGettingUpdates false
# WebhookHost "https://real.url.com"
# WebhookPort "443"
# WebhookURL "/bot/telegram-bot-token"
# MHDDaemonHost "localhost"
# MHDDaemonPort "8000"
# RecipientChatID "123123123"
# RecipientChatID "-1424242424242"
#</Plugin>

#<Plugin ntpd>
# Host "localhost"
# Port 123
Expand Down
56 changes: 56 additions & 0 deletions src/collectd.conf.pod
Original file line number Diff line number Diff line change
Expand Up @@ -6802,6 +6802,62 @@ Sets the I<command file> to write to. Defaults to F</usr/local/nagios/var/rw/nag

=back

=head2 Plugin C<notify_telegram>

The I<notify_telegram> plugin uses I<libcurl> and Telegram Bot API to send notifications to configured Telegram users.
It also can send config instruction with ChatID in response to all users, either by long polling, or by using webhooks that utilize I<libcurl>, I<libyajl>, I<libmicrohttpd>.

Read more about Telegram Bot API L<https://core.telegram.org/bots/api>.

Available configuration options:

=over 9

=item B<BotToken> I<Token>

Telegram Bot token.

=item B<RecipientChatID> I<ID>

Configures the Telegram chats to which the notifications should be send.
May be repeated to send notifications to multiple chats.

=item B<ProxyURL> I<URL>

Telegram proxy adress to connect to.

Default: C<https://api.telegram.org/bot>

=item B<DisableGettingUpdates> I<true>|I<false>

Disable the processing of messages from users to the bot.

Default: C<false>

=item B<WebhookHost> I<Host>

The host to which Telegram will send updates via webhooks. Do not specify if you do not want to use the webhooks.

=item B<WebhookPort> I<Port>

Port for webhook host. Do not specify if you do not want to use the webhooks.

Default: C<443>

=item B<WebhookURL> I<URL>

The URL after the host and port to which Telegram will send updates via webhooks. Do not specify if you do not want to use the webhooks.

=item B<MHDDaemonHost> I<Host>

The host for starting the http server. Do not specify if you do not want to use the webhooks.

=item B<MHDDaemonPort> I<Port>

The port for starting the http server. Do not specify if you do not want to use the webhooks.

=back

=head2 Plugin C<ntpd>

The C<ntpd> plugin collects per-peer ntp data such as time offset and time
Expand Down

0 comments on commit eb98405

Please sign in to comment.