atc0005 / go-nagios

Shared Golang package for Nagios plugins
MIT License
8 stars 3 forks source link

Add helper functions for converting common Nagios date/time formats? #185

Open atc0005 opened 1 year ago

atc0005 commented 1 year ago

While reading https://www.devopsschool.com/tutorial/nagios/nagios-faq.html I found this:

Q. When Does Nagios Check For External Commands?

Ans: At regular intervals specified by the command_check_interval option in the main configuration file Immediately after event handlers are executed. This is in addition to the regular cycle of external command checks and is done to provide immediate action if an event handler submits commands to Nagios. External commands that are written to the command file have the following format [time] command_id;command_arguments where time is the time (in time_t format) that the external application submitted the external command to the command file. The values for the command_id and command_arguments arguments will depend on what command is being submitted to Nagios.

and this specific tidbit:

External commands that are written to the command file have the following format [time] command_id;command_arguments where time is the time (in time_t format)

which reminded me of this CLI "recipe" (where example1 in the example is the hostname):

$ grep -i example1 /usr/local/nagios/var/nagios.log | perl -pe 's/(\d+)/localtime($1)/e'

It would be useful to provide a helper for converting the time_t format to other commonly used formats.

atc0005 commented 1 year ago

While attempting to create a scratch Go file I found this stubbed out:

package main

import (
        "fmt"
        "time"
)

func main() {
        t := time.Unix(1663514401, 0)
        fmt.Println(t)
}

Noting it here for a reminder of where to start looking.