diff --git a/Untitled-1.xml b/Untitled-1.xml new file mode 100644 index 0000000..ad67daf --- /dev/null +++ b/Untitled-1.xml @@ -0,0 +1,32 @@ + +1.0 +TI +yes + + +liverm.skyti.ticdn.it + + +liverm.skyti.ticdn.it +index + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/go-nagrapi b/go-nagrapi index 456f6df..5fba6e6 100755 Binary files a/go-nagrapi and b/go-nagrapi differ diff --git a/main.go b/main.go index 20994bf..be3161c 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "encoding/json" "flag" "net/http" + "strconv" "github.com/cxfcxf/nagtomaps" "github.com/zenazn/goji" @@ -22,16 +23,22 @@ type Host struct { // Service ... type Service struct { - Name string `json:"name,omitempty"` - CurrentState string `json:"current_state,omitempty"` + Name string `json:"name,omitempty"` + //modified to *int in order to have json correctly identify the 0 value as a real value and not nil + CurrentState *int `json:"current_state,omitempty"` } var statusFile = flag.String("s", "/data/status.dat", "Specify the location of the status file") +//added the n flag to have as output only services with that level of issue +var nagiosstate = flag.Int("n", 0, "Specify the number Nagios uses to describe the status [0, 1, 2, 3]") + // GetState ... func GetState(w http.ResponseWriter, r *http.Request) { // Parse the status file sdata := nagtomaps.ParseStatus(*statusFile) + //needed to have a int value to check it against nagios status level + nagstatus := *nagiosstate hostResponse := &Response{ Hosts: nil, @@ -44,13 +51,21 @@ func GetState(w http.ResponseWriter, r *http.Request) { } for name2, object2 := range sdata.Servicestatuslist[name] { + + //if the state of the service does not match with the one in input interrupts the loop + currstateint, _ := strconv.Atoi(object2["current_state"]) + if currstateint != nagstatus { + continue + } if object2["host_name"] == host.Name { + service := &Service{ Name: name2, - CurrentState: object2["current_state"], + CurrentState: &currstateint, } host.Services = append(host.Services, service) + } }