stub out /powersource and /lastoutage

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-06 10:28:16 -05:00
parent f255120c10
commit 7b196bca76
4 changed files with 22 additions and 14 deletions

2
.gitignore vendored
View File

@ -2,4 +2,4 @@
go.mod go.mod
go.sum go.sum
power powerpaneld

View File

@ -2,7 +2,7 @@ all:
-git pull -git pull
echo "build it!" echo "build it!"
GO111MODULE=off go build -v -x GO111MODULE=off go build -v -x
./power ./powerpaneld
# su -c "setcap 'cap_net_bind_service=+ep' go.wit.com" # su -c "setcap 'cap_net_bind_service=+ep' go.wit.com"
goimports: goimports:

9
control Normal file
View File

@ -0,0 +1,9 @@
Source: powerpaneld
Build-Depends: golang
Package: powerpaneld
Maintainer: Jeff Carr <jcarr@wit.com>
Architecture: amd64
Depends: powerpanel
Description: serves cyberpower UPS data on http for uptime checks
simply dumps the status of the UPS to port 3000 so uptime checks
can monitor utility power grid failures

23
main.go
View File

@ -3,19 +3,17 @@ package main
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"os"
"strings" "strings"
"time" "time"
"go.wit.com/log" "go.wit.com/log"
) )
var accessf, clientf *os.File // var accessf, clientf *os.File
var repoMap map[string]string // var repoMap map[string]string
var versionMap map[string]string // var versionMap map[string]string
var configfile []string // var keysSorted []string
var keysSorted []string
// remove '?' part and trailing '/' // remove '?' part and trailing '/'
func cleanURL(url string) string { func cleanURL(url string) string {
@ -24,9 +22,7 @@ func cleanURL(url string) string {
} }
func okHandler(w http.ResponseWriter, r *http.Request) { func okHandler(w http.ResponseWriter, r *http.Request) {
// dumpClient(r)
var tmp string var tmp string
// tmp = r.URL.String()
tmp = cleanURL(r.URL.Path) tmp = cleanURL(r.URL.Path)
parts := strings.Split(tmp, "?") parts := strings.Split(tmp, "?")
log.Warn("URL =", tmp) log.Warn("URL =", tmp)
@ -34,18 +30,21 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
log.Info("parts are:", parts) log.Info("parts are:", parts)
// requrl := parts[0] // requrl := parts[0]
if tmp == "/power" { if tmp == "/powersource" {
fmt.Fprintln(w, "BAD ZOOT") fmt.Fprintln(w, "Utility Power")
return return
} }
fmt.Fprintln(w, "BAD URL", tmp) if tmp == "/lastoutage" {
fmt.Fprintln(w, "Blackout at 2024/09/25 20:21:57 for 33 sec.")
return
}
fmt.Fprintln(w, "UNKNOWN URL:", tmp)
// log.Warn("BAD URL =", url, "REPO URL =", repourl) // log.Warn("BAD URL =", url, "REPO URL =", repourl)
// badurl(w, r.URL.String()) // badurl(w, r.URL.String())
// fmt.Fprintln(w, "BAD", tmp) // fmt.Fprintln(w, "BAD", tmp)
} }
func main() { func main() {
log.Println("found log =", versionMap["go.wit.com/log"])
http.HandleFunc("/", okHandler) http.HandleFunc("/", okHandler)
err := http.ListenAndServe(":3000", nil) err := http.ListenAndServe(":3000", nil)
if err != nil { if err != nil {