Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added filter for Nagios error level #1

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
32 changes: 32 additions & 0 deletions Untitled-1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<CDSRules xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="schema\CDSRules.xsd">
<Revision>1.0</Revision>
<CustomerName>TI</CustomerName>
<ApplyAllTier>yes</ApplyAllTier>
<Rule_Patterns>
<PatternListGrp id="grp1">
<Domain>liverm.skyti.ticdn.it</Domain>
</PatternListGrp>
<PatternListGrp id="grp3">
<Domain>liverm.skyti.ticdn.it</Domain>
<UrlRegex>index</UrlRegex>
</PatternListGrp>
</Rule_Patterns>
<Rule_Actions>
<Rule_Validate matchGroup="grp3" key="cisco123" protocol="all" error-redirect-url=""/>
<Rule_Allow matchGroup="grp1,grp3" protocol="http"/>
<Rule_SetAction name="Rule_DSConfig" matchGroup="grp1,grp3" protocol="http">
<SetParameter name="SessionResolveRule#1" value="index(.*):none"/>
<SetParameter name="SessionProtocol#1" value=".*:protocol=$generic_hls"/>
<SetParameter name="SessionInactivityTimeout" value="400"/>
<SetParameter name="StreamerSecretKey" value="1A2B3C4a5b6c7d8e9900A1B1C1D1E1C1"/>
<SetParameter name="SessionClientIpCheckEnable" value="1"/>
<SetParameter name="GenericSessionAccessProtect#1" value=".*.m3u8:none"/>
<SetParameter name="GenericSessionAccessProtect#2" value=".*.ts:none"/>
<SetParameter name="SessionSinfoTimeout" value="300"/>
<SetParameter name="SessionIdleTimeout" value="420"/>
<SetParameter name="SessionCookieTrackingEnable" value="1"/>
<SetParameter name="SessionCookieRefreshThreshold" value="0.6"/>
<SetParameter name="SessionManifestURIFailoverEnable" value="0"/>
</Rule_SetAction>
</Rule_Actions>
</CDSRules>
Binary file modified go-nagrapi
Binary file not shown.
21 changes: 18 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"flag"
"net/http"
"strconv"

"github.com/cxfcxf/nagtomaps"
"github.com/zenazn/goji"
Expand All @@ -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,
Expand All @@ -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)

}
}

Expand Down