Skip to content
Merged
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
8 changes: 7 additions & 1 deletion get_nagios_version/get_nagios_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ package get_nagios_version
import (
"net/http"
"strings"
"time"

"golang.org/x/net/html"
)

func GetLatestNagiosXIVersion(NagiosXIURL string) (version string, err error) {

// Initialize a client with a timeout in case of connection issues
client := &http.Client{
Timeout: 10 * time.Second,
}

// Fetch the HTML source data from the URL
resp, err := http.Get(NagiosXIURL)
resp, err := client.Get(NagiosXIURL)
if err != nil {
return "", err
}
Expand Down
16 changes: 11 additions & 5 deletions nagios_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,17 @@ func (e *Exporter) QueryAPIsAndUpdateMetrics(ch chan<- prometheus.Metric, sslVer
log.Warn(err)
}

updateMetric := CompareNagiosVersions(nagiosVersion, systemInfoObject.Version)
ch <- prometheus.MustNewConstMetric(
updateAvailable, prometheus.GaugeValue, updateMetric,
// updateMetric 0 = no update, updateMetric 1 = update available
)
// Ensure that nagiosVersion is not empty before comparing versions/updating the metric
if nagiosVersion != "" {
updateMetric := CompareNagiosVersions(nagiosVersion, systemInfoObject.Version)
ch <- prometheus.MustNewConstMetric(
updateAvailable, prometheus.GaugeValue, updateMetric,
// updateMetric 0 = no update, updateMetric 1 = update available
)
}

log.Warn("Nagios version wasn't found, not updating `nagios_update_available_info` metric")

} else { // user did not want to compare nagios versions externally so just say there aren't any updates (0)
ch <- prometheus.MustNewConstMetric(
updateAvailable, prometheus.GaugeValue, 0,
Expand Down
Loading