Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature ms teams appender #52

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Suggests:
rsyslog,
shiny,
callr,
httr,
txtq,
botor,
R.utils
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions R/appenders.R
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,30 @@

}

#' 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,

Check warning on line 445 in R/appenders.R

View check run for this annotation

Codecov / codecov/patch

R/appenders.R#L441-L445

Added lines #L441 - L445 were not covered by tests
## 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"

Check warning on line 449 in R/appenders.R

View check run for this annotation

Codecov / codecov/patch

R/appenders.R#L448-L449

Added lines #L448 - L449 were not covered by tests
),
generator = deparse(match.call())

Check warning on line 451 in R/appenders.R

View check run for this annotation

Codecov / codecov/patch

R/appenders.R#L451

Added line #L451 was not covered by tests
)
}

## TODO other appenders: graylog, datadog, cloudwatch, email via sendmailR, ES etc
26 changes: 26 additions & 0 deletions man/appender_ms_teams.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.