-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:wbollock/nagios_exporter into docs/…
…update_readme
- Loading branch information
Showing
9 changed files
with
298 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Go Test | ||
|
||
on: | ||
push: | ||
tags: | ||
- v* | ||
branches: [main] | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: '1.19' | ||
|
||
- name: Install dependencies | ||
run: go mod download | ||
|
||
- name: Run tests | ||
run: go test ./tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
repos: | ||
- repo: https://github.com/tekwizely/pre-commit-golang | ||
rev: v1.0.0-rc.1 | ||
hooks: | ||
# | ||
# Go Build | ||
# | ||
- id: go-build-mod | ||
- id: go-build-repo-mod | ||
# | ||
# Go Mod Tidy | ||
# | ||
- id: go-mod-tidy | ||
- id: go-mod-tidy-repo | ||
# | ||
# Go Test | ||
# | ||
- id: go-test-mod | ||
- id: go-test-repo-mod | ||
# | ||
# Formatters | ||
# | ||
- id: go-fmt | ||
- id: go-fmt-repo | ||
# | ||
# | ||
# GolangCI-Lint | ||
# - Fast Multi-Linter | ||
# - Can be configured to replace MOST other hooks | ||
# - Supports repo config file for configuration | ||
# - https://github.com/golangci/golangci-lint | ||
# | ||
- id: golangci-lint | ||
- id: golangci-lint-mod | ||
- id: golangci-lint-repo-mod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package get_nagios_version | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"golang.org/x/net/html" | ||
) | ||
|
||
func GetLatestNagiosXIVersion(NagiosXIURL string) (version string, err error) { | ||
|
||
// Fetch the HTML source data from the URL | ||
resp, err := http.Get(NagiosXIURL) | ||
if err != nil { | ||
fmt.Println("Error fetching HTML:", err) | ||
return | ||
} | ||
defer resp.Body.Close() | ||
|
||
// Parse the HTML data into a tree structure | ||
doc, err := html.Parse(resp.Body) | ||
if err != nil { | ||
log.Info(err) | ||
return "", err | ||
} | ||
|
||
// https://pkg.go.dev/golang.org/x/net/html#Parse | ||
// recursive function seems to be best practice | ||
var traverse func(*html.Node) string | ||
traverse = func(node *html.Node) string { | ||
if node.Type == html.TextNode { | ||
if strings.HasPrefix(node.Data, "xi-") { | ||
// the first `xi-` string is the latest NagiosXI version in semver | ||
return node.Data | ||
} | ||
} | ||
for child := node.FirstChild; child != nil; child = child.NextSibling { | ||
result := traverse(child) | ||
if result != "" { | ||
return result | ||
} | ||
} | ||
return "" | ||
} | ||
|
||
// traverse the HTML parse tree and return the version if found | ||
version = traverse(doc) | ||
|
||
return version, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.