Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
2.9 kB ยท 122 lines
Go
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123package main
import ( _ "embed" "encoding/json" "fmt" "io" "log" "net/http"
"github.com/gliderlabs/ssh")
//go:embed banner.txtvar banner string
func bannerfunc(ctx ssh.Context) string { return banner}
var statusOk = `+----------------------------------+| || All Systems Operational || |+----------------------------------+`var statusDegraded = `+----------------------------------+| || System is degraded || |+----------------------------------+`var statusPartialOutage = `+----------------------------------+| || System is partially out of || service || |+----------------------------------+`var statusMajorOutage = `+----------------------------------+| || System is out of service || |+----------------------------------+`var statusUnderMaintenance = `+----------------------------------+| || System is under || maintenance || |+----------------------------------+`var statusIncident = `+----------------------------------+| || System is partially out of || service || |+----------------------------------+`
type status struct { Status string `json:"status"`}
func handler(s ssh.Session) { url := fmt.Sprintf("https://api.openstatus.dev/public/status/%s", s.User()) res, err := http.Get(url) if err != nil { fmt.Fprintf(s, "Error fetching status: %v\n", err) return } defer res.Body.Close() var status status json.NewDecoder(res.Body).Decode(&status)
var currentStatus string switch status.Status { case "operational": currentStatus = statusOk case "degraded_performance": currentStatus = statusDegraded case "partial_outage": currentStatus = statusPartialOutage case "major_outage": currentStatus = statusMajorOutage case "under_maintenance": currentStatus = statusUnderMaintenance case "incident": currentStatus = statusIncident default: currentStatus = "" }
if currentStatus == "" { io.WriteString(s, "Unknown status page") return }
io.WriteString(s, fmt.Sprintf("\nCurrent Status for: %s\n\n%s\n\nVisit the status page at https://%s.openstatus.dev/\n\n", s.User(), currentStatus, s.User()))}
func main() {
server := &ssh.Server{ Addr: ":2222", BannerHandler: bannerfunc, Handler: handler,
} ssh.HostKeyFile("/data/id_rsa")
log.Println("starting ssh server on port 2222...") log.Fatal(server.ListenAndServe())
}