-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from nixys/master
feat(PR #7): Add API method for Problem
- Loading branch information
Showing
9 changed files
with
216 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/.project | ||
/.vscode | ||
.project | ||
.vscode | ||
.idea | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package zabbix | ||
|
||
type EventAcknowledgeActionType int64 | ||
|
||
const ( | ||
EventAcknowledgeActionTypeClose EventAcknowledgeActionType = 1 | ||
EventAcknowledgeActionTypeAck EventAcknowledgeActionType = 2 | ||
EventAcknowledgeActionTypeAddMessage EventAcknowledgeActionType = 4 | ||
EventAcknowledgeActionTypeChangeSeverity EventAcknowledgeActionType = 8 | ||
EventAcknowledgeActionTypeUnack EventAcknowledgeActionType = 16 | ||
EventAcknowledgeActionTypeSuppress EventAcknowledgeActionType = 32 | ||
EventAcknowledgeActionTypeUnsuppress EventAcknowledgeActionType = 64 | ||
EventAcknowledgeActionTypeChangeEventRankCause EventAcknowledgeActionType = 128 | ||
EventAcknowledgeActionTypeChangeEventRankSymptom EventAcknowledgeActionType = 256 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module github.com/nixys/nxs-go-zabbix/v5 | ||
|
||
go 1.14 | ||
go 1.20 | ||
|
||
require github.com/mitchellh/mapstructure v1.3.0 | ||
require github.com/mitchellh/mapstructure v1.5.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
github.com/mitchellh/mapstructure v1.3.0 h1:iDwIio/3gk2QtLLEsqU5lInaMzos0hDTz8a6lazSFVw= | ||
github.com/mitchellh/mapstructure v1.3.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= | ||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= | ||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package zabbix | ||
|
||
type ProblemSourceType int64 | ||
|
||
const ( | ||
ProblemSourceTypeTrigger ProblemSourceType = 0 | ||
ProblemSourceTypeInternal ProblemSourceType = 3 | ||
ProblemSourceTypeServiceStatusUpdate ProblemSourceType = 4 | ||
) | ||
|
||
type ProblemObjectType int64 | ||
|
||
const ( | ||
ProblemObjectTypeTrigger ProblemObjectType = 0 | ||
ProblemObjectTypeItem ProblemObjectType = 4 | ||
ProblemObjectTypeLLDRule ProblemObjectType = 5 | ||
ProblemObjectTypeService ProblemObjectType = 6 | ||
) | ||
|
||
type ProblemAcknowledgeType int64 | ||
|
||
const ( | ||
ProblemAcknowledgeTypeFalse ProblemAcknowledgeType = 0 | ||
ProblemAcknowledgeTypeTrue ProblemAcknowledgeType = 1 | ||
) | ||
|
||
type ProblemSeverityType int64 | ||
|
||
const ( | ||
ProblemSeverityTypeNotClassified ProblemSeverityType = 0 | ||
ProblemSeverityTypeInformation ProblemSeverityType = 1 | ||
ProblemSeverityTypeWarning ProblemSeverityType = 2 | ||
ProblemSeverityTypeAverage ProblemSeverityType = 3 | ||
ProblemSeverityTypeHigh ProblemSeverityType = 4 | ||
ProblemSeverityTypeDisaster ProblemSeverityType = 5 | ||
) | ||
|
||
type ProblemSuppressedType int64 | ||
|
||
const ( | ||
ProblemSuppressedTypeNormalState ProblemSuppressedType = 0 | ||
ProblemSuppressedTypeSuppressed ProblemSuppressedType = 1 | ||
) | ||
|
||
type ProblemEvalType int64 | ||
|
||
const ( | ||
ProblemEvalTypeAndOr ProblemEvalType = 0 | ||
ProblemEvalTypeOR ProblemEvalType = 2 | ||
) | ||
|
||
// ProblemObject struct is used to store problem operations results | ||
// | ||
// see: https://www.zabbix.com/documentation/5.0/en/manual/api/reference/problem/object | ||
type ProblemObject struct { | ||
EventID int64 `json:"eventid,omitempty"` | ||
Source ProblemSourceType `json:"source,omitempty"` | ||
Object ProblemObjectType `json:"object,omitempty"` | ||
ObjectID int64 `json:"objectid,omitempty"` | ||
Clock int64 `json:"clock,omitempty"` | ||
Ns int64 `json:"ns,omitempty"` | ||
REventID int64 `json:"r_eventid,omitempty"` | ||
RClock int64 `json:"r_clock,omitempty"` | ||
RNs int64 `json:"r_ns,omitempty"` | ||
CauseEventID int64 `json:"cause_eventid,omitempty"` | ||
CorrelationID int64 `json:"correlationid,omitempty"` | ||
UserID int64 `json:"userid,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
Acknowledged ProblemAcknowledgeType `json:"acknowledged,omitempty"` | ||
Severity ProblemSeverityType `json:"severity,omitempty"` | ||
Suppressed ProblemSuppressedType `json:"suppressed,omitempty"` | ||
OpData string `json:"opdata,omitempty"` | ||
URLs []ProblemMediaTypeURLObject `json:"urls,omitempty"` | ||
Acknowledges []ProblemAcknowledgeObject `json:"acknowledges,omitempty"` | ||
Tags []ProblemTagObject `json:"tags,omitempty"` | ||
Suppression []ProblemSuppressionObject `json:"suppression_data,omitempty"` | ||
} | ||
|
||
type ProblemAcknowledgeObject struct { | ||
AcknowledgeID int64 `json:"acknowledgeid,omitempty"` | ||
UserID int64 `json:"userid,omitempty"` | ||
EventID int64 `json:"eventid,omitempty"` | ||
Clock int64 `json:"clock,omitempty"` | ||
Message string `json:"message,omitempty"` | ||
Action EventAcknowledgeActionType `json:"action,omitempty"` | ||
OldSeverity ProblemSeverityType `json:"old_severity,omitempty"` | ||
NewSeverity ProblemSeverityType `json:"new_severity,omitempty"` | ||
SuppressUntil int64 `json:"suppress_until,omitempty"` | ||
TaskID int64 `json:"taskid,omitempty"` | ||
} | ||
|
||
type ProblemMediaTypeURLObject struct { | ||
Name string `json:"name,omitempty"` | ||
URL string `json:"url,omitempty"` | ||
} | ||
|
||
type ProblemTagObject struct { | ||
Tag string `json:"tag,omitempty"` | ||
Value string `json:"value,omitempty"` | ||
} | ||
|
||
type ProblemSuppressionObject struct { | ||
MaintenanceID int64 `json:"maintenanceid,omitempty"` | ||
UserID int64 `json:"userid,omitempty"` | ||
SuppressUntil int64 `json:"suppress_until,omitempty"` | ||
} | ||
|
||
// ProblemGetParams struct is used for problem get requests | ||
// | ||
// see: https://www.zabbix.com/documentation/5.0/en/manual/api/reference/problem/get#parameters | ||
type ProblemGetParams struct { | ||
GetParameters | ||
|
||
EventIDs []int64 `json:"eventids,omitempty"` | ||
GroupIDs []int64 `json:"groupids,omitempty"` | ||
HostIDs []int64 `json:"hostids,omitempty"` | ||
ObjectIDs []int64 `json:"objectids,omitempty"` | ||
ApplicationIDs []int64 `json:"applicationids,omitempty"` | ||
Source ProblemSourceType `json:"source,omitempty"` | ||
Object ProblemObjectType `json:"object,omitempty"` | ||
Acknowledged bool `json:"acknowledged,omitempty"` | ||
Suppressed bool `json:"suppressed,omitempty"` | ||
Severities []ProblemSeverityType `json:"severities,omitempty"` | ||
Evaltype ProblemEvalType `json:"evaltype,omitempty"` | ||
Tags []ProblemTagObject `json:"tags,omitempty"` | ||
Recent bool `json:"recent,omitempty"` | ||
EventIDFrom int64 `json:"eventid_from,omitempty"` | ||
EventIDTill int64 `json:"eventid_till,omitempty"` | ||
TimeFrom int64 `json:"time_from,omitempty"` | ||
TimeTill int64 `json:"time_till,omitempty"` | ||
SelectAcknowledges SelectQuery `json:"selectAcknowledges,omitempty"` | ||
SelectTags SelectQuery `json:"selectTags,omitempty"` | ||
SelectSuppressionData SelectQuery `json:"selectSuppressionData,omitempty"` | ||
SortField []string `json:"sortfield,omitempty"` | ||
} | ||
|
||
// ProblemGet gets problems | ||
func (z *Context) ProblemGet(params ProblemGetParams) ([]ProblemObject, int, error) { | ||
|
||
var result []ProblemObject | ||
|
||
status, err := z.request("problem.get", params, &result) | ||
if err != nil { | ||
return nil, status, err | ||
} | ||
|
||
return result, status, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package zabbix | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestProblemCRUD(t *testing.T) { | ||
|
||
var z Context | ||
|
||
// Login | ||
loginTest(&z, t) | ||
defer logoutTest(&z, t) | ||
|
||
// Get | ||
testProblemGet(t, z) | ||
} | ||
|
||
func testProblemGet(t *testing.T, z Context) { | ||
|
||
pObjects, _, err := z.ProblemGet(ProblemGetParams{ | ||
//ObjectIDs: []int{20143}, | ||
// ... Add other fields as needed | ||
}) | ||
|
||
if err != nil { | ||
t.Error("Problem get error:", err) | ||
} else { | ||
if len(pObjects) == 0 { | ||
t.Error("Problem get error: unable to find problems") | ||
} else { | ||
t.Logf("Problem get: success") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters