diff --git a/DESCRIPTION b/DESCRIPTION index e4e5c88f..48099555 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -33,6 +33,7 @@ Suggests: rsyslog, shiny, callr, + httr, txtq, botor, R.utils diff --git a/NAMESPACE b/NAMESPACE index fea5a9f1..0826112d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -12,6 +12,7 @@ export(appender_async) export(appender_console) export(appender_file) export(appender_kinesis) +export(appender_ms_teams) export(appender_pushbullet) export(appender_slack) export(appender_stderr) diff --git a/R/appenders.R b/R/appenders.R index c021aa58..555bdbef 100644 --- a/R/appenders.R +++ b/R/appenders.R @@ -426,4 +426,30 @@ appender_async <- function(appender, batch = 1, namespace = 'async_logger', } +#' Send log messages to Microsoft Teams Incoming Webhook +#' +#' @param teams_webhook_url character, url to the incoming webhook you would like to use +#' +#' You must create an incoming webhook for the Microsoft Teams channel you want to send log messages +#' to. For instructions on how to do this, visit the \href{https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook#add-an-incoming-webhook-to-a-teams-channel}{Microsoft Teams documentation page}. +#' +#' @return function taking lines as argument +#' @export +#' @note This functionality depends on the \pkg{httr} package. +#' @seealso This is generator function for \code{\link{log_appender}}, for alternatives, see eg \code{\link{appender_console}}, \code{\link{appender_file}}, \code{\link{appender_tee}}, \code{\link{appender_slack}}, \code{\link{appender_telegram}}, \code{\link{appender_syslog}}, \code{\link{appender_kinesis}} and \code{\link{appender_async}} for evaluate any \code{\link{log_appender}} function in a background process. +appender_ms_teams <- function(teams_webhook_url) { + fail_on_missing_package('httr') + force(teams_webhook_url) + structure( + function(lines) + httr::POST(url = teams_webhook_url, + ## NOTE MS Teams will parse our input as Markdown text, so we need to use 2 spaces before the newline + ## It may be a good idea to escape characters that have special meaning in Markdown + body = list(text = paste0(lines, collapse = " \n")), + encode = "json" + ), + generator = deparse(match.call()) + ) +} + ## TODO other appenders: graylog, datadog, cloudwatch, email via sendmailR, ES etc diff --git a/man/appender_ms_teams.Rd b/man/appender_ms_teams.Rd new file mode 100644 index 00000000..c3aa7b8a --- /dev/null +++ b/man/appender_ms_teams.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/appenders.R +\name{appender_ms_teams} +\alias{appender_ms_teams} +\title{Send log messages to Microsoft Teams Incoming Webhook} +\usage{ +appender_ms_teams(teams_webhook_url) +} +\arguments{ +\item{teams_webhook_url}{character, url to the incoming webhook you would like to use + +You must create an incoming webhook for the Microsoft Teams channel you want to send log messages +to. For instructions on how to do this, visit the \href{https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook#add-an-incoming-webhook-to-a-teams-channel}{Microsoft Teams documentation page}.} +} +\value{ +function taking lines as argument +} +\description{ +Send log messages to Microsoft Teams Incoming Webhook +} +\note{ +This functionality depends on the \pkg{httr} package. +} +\seealso{ +This is generator function for \code{\link{log_appender}}, for alternatives, see eg \code{\link{appender_console}}, \code{\link{appender_file}}, \code{\link{appender_tee}}, \code{\link{appender_slack}}, \code{\link{appender_telegram}}, \code{\link{appender_syslog}}, \code{\link{appender_kinesis}} and \code{\link{appender_async}} for evaluate any \code{\link{log_appender}} function in a background process. +}