atc0005 / send2teams

Small CLI tool used to submit messages to Microsoft Teams.
MIT License
25 stars 1 forks source link

Add support for logging to a file #226

Open atc0005 opened 2 years ago

atc0005 commented 2 years ago

This could be useful for troubleshooting messages delivered by another tool such as Nagios Core that (afaik) doesn't capture output from executed notification commands.

atc0005 commented 2 years ago

Note: Have example use the same directory as the value for log_file from nagios.cfg.

For example:

# LOG FILE
# This is the main log file where service and host events are logged
# for historical purposes.  This should be the first option specified 
# in the config file!!!

log_file=/var/log/nagios3/nagios.log

In our case, /var/log/nagios3/send2teams.log should be the fully-qualified log file path used in the example(s). Specifying /tmp/send2teams.log may not work for Nagios' purposes unless SELinux or AppArmor policy changes are applied to permit that access.

atc0005 commented 2 years ago

Snippet used for debugging/troubleshooting work on #225:

    f, err := os.OpenFile("/var/log/nagios3/send2teams.log",
        os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
    if err != nil {
        log.Println(err)
    }

    defer f.Close()
    log.SetOutput(f)

Needs work:

The fixed path/filename would be replaced with a user-specified value and sanitized where possible.