Skip to content

Commit

Permalink
Merge pull request vbatoufflet#3 from tcolgate/master
Browse files Browse the repository at this point in the history
Add WaitCondition* and Limit query options
  • Loading branch information
vbatoufflet authored Jun 13, 2016
2 parents e88c66a + 17401cd commit 80a012a
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net"
"strconv"
"strings"
"time"
)

// Query is a binding query instance.
Expand Down Expand Up @@ -49,6 +50,60 @@ func (q *Query) Negate() *Query {
return q
}

// Limit the query to n responses.
func (q *Query) Limit(n int) *Query {
q.headers = append(q.headers, fmt.Sprintf("Limit: %d", n))
return q
}

// WaitObject sets the object within the queried table to wait on. For the table
// hosts, hostgroups, servicegroups, contacts and contactgroups this is simply
// the name of the object. For the table services it is the hostname followed
// by a space followed by the service description
func (q *Query) WaitObject(obj string) *Query {
q.headers = append(q.headers, "WaitObject: "+obj)
return q
}

// WaitCondition sets a new wait condition to apply to the query.
func (q *Query) WaitCondition(rule string) *Query {
q.headers = append(q.headers, "WaitCondition: "+rule)
return q
}

// WaitConditionAnd combines the n last wait conditions into a new wait
// condition using a `And` operation.
func (q *Query) WaitConditionAnd(n int) *Query {
q.headers = append(q.headers, fmt.Sprintf("WaitConditionAnd: %d", n))
return q
}

// WaitConditionOr combines the n last wait condition into a new wait condition
// using a `Or` operation.
func (q *Query) WaitConditionOr(n int) *Query {
q.headers = append(q.headers, fmt.Sprintf("WaitConditionOr: %d", n))
return q
}

// WaitConditionNegate negates the most recent wait condition.
func (q *Query) WaitConditionNegate() *Query {
q.headers = append(q.headers, "WaitConditionNegate:")
return q
}

// WaitTrigger sets the nagios event that will trigger a check of
// the wait condition.
func (q *Query) WaitTrigger(event string) *Query {
q.headers = append(q.headers, "WaitTrigger: "+event)
return q
}

// WaitTimeout set a timeout for the wait condition.
func (q *Query) WaitTimeout(t time.Duration) *Query {
q.headers = append(q.headers, fmt.Sprintf("WaitTimeout: %d", t/time.Millisecond))
return q
}

// Exec executes the query.
func (q *Query) Exec() (*Response, error) {
resp := &Response{}
Expand Down

0 comments on commit 80a012a

Please sign in to comment.