Skip to content

Commit

Permalink
Sapcontrol gatherer (#270)
Browse files Browse the repository at this point in the history
* Add new sapcontrol webmethods to api

* Create sapcontrol gatherer

* Add sapcontrol gatherer in list of gatherers

* Extract instanceName and instanceNumber to vars

* Improve error logs

* Add brackets to switch to improve readbility

* Restructure code to use ifs instead of switch
  • Loading branch information
arbulu89 authored Oct 10, 2023
1 parent 3135b1e commit f41d120
Show file tree
Hide file tree
Showing 5 changed files with 1,094 additions and 0 deletions.
69 changes: 69 additions & 0 deletions internal/core/sapsystem/sapcontrolapi/mocks/WebService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 95 additions & 0 deletions internal/core/sapsystem/sapcontrolapi/webservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,31 @@ type WebService interface {
GetInstanceProperties() (*GetInstancePropertiesResponse, error)
GetProcessList() (*GetProcessListResponse, error)
GetSystemInstanceList() (*GetSystemInstanceListResponse, error)
GetVersionInfo() (*GetVersionInfoResponse, error)
HACheckConfig() (*HACheckConfigResponse, error)
HAGetFailoverConfig() (*HAGetFailoverConfigResponse, error)
}

type STATECOLOR string
type STATECOLOR_CODE int
type HAVerificationState string
type HACheckCategory string

const (
STATECOLOR_GRAY STATECOLOR = "SAPControl-GRAY"
STATECOLOR_GREEN STATECOLOR = "SAPControl-GREEN"
STATECOLOR_YELLOW STATECOLOR = "SAPControl-YELLOW"
STATECOLOR_RED STATECOLOR = "SAPControl-RED"

HAVerificationStateSAPControlHASUCCESS HAVerificationState = "SAPControl-HA-SUCCESS"
HAVerificationStateSAPControlHAWARNING HAVerificationState = "SAPControl-HA-WARNING"
HAVerificationStateSAPControlHAERROR HAVerificationState = "SAPControl-HA-ERROR"

HACheckCategorySAPControlSAPCONFIGURATION HACheckCategory = "SAPControl-SAP-CONFIGURATION"
HACheckCategorySAPControlSAPSTATE HACheckCategory = "SAPControl-SAP-STATE"
HACheckCategorySAPControlHACONFIGURATION HACheckCategory = "SAPControl-HA-CONFIGURATION"
HACheckCategorySAPControlHASTATE HACheckCategory = "SAPControl-HA-STATE"

// NOTE: This was just copy-pasted from sap_host_exporter, not used right now
// see: https://github.com/SUSE/sap_host_exporter/blob/68bbf2f1b490ab0efaa2dd7b878b778f07fba2ab/lib/sapcontrol/webservice.go#L42
STATECOLOR_CODE_GRAY STATECOLOR_CODE = 1
Expand Down Expand Up @@ -65,6 +79,38 @@ type GetSystemInstanceListResponse struct {
Instances []*SAPInstance `xml:"instance>item,omitempty" json:"instance>item,omitempty"`
}

type GetVersionInfo struct {
XMLName xml.Name `xml:"urn:SAPControl GetVersionInfo"`
}

type GetVersionInfoResponse struct {
XMLName xml.Name `xml:"urn:SAPControl GetVersionInfoResponse"`
InstanceVersions []*VersionInfo `xml:"version>item,omitempty" json:"version>item,omitempty"`
}

type HACheckConfig struct {
XMLName xml.Name `xml:"urn:SAPControl HACheckConfig"`
}

type HACheckConfigResponse struct {
XMLName xml.Name `xml:"urn:SAPControl HACheckConfigResponse"`
Checks []*HACheck `xml:"check>item,omitempty" json:"check>item,omitempty"`
}

type HAGetFailoverConfig struct {
XMLName xml.Name `xml:"urn:SAPControl HAGetFailoverConfig"`
}

type HAGetFailoverConfigResponse struct {
XMLName xml.Name `xml:"urn:SAPControl HAGetFailoverConfigResponse"`
HAActive bool `xml:"HAActive,omitempty" json:"HAActive,omitempty"`
HAProductVersion string `xml:"HAProductVersion,omitempty" json:"HAProductVersion,omitempty"`
HASAPInterfaceVersion string `xml:"HASAPInterfaceVersion,omitempty" json:"HASAPInterfaceVersion,omitempty"`
HADocumentation string `xml:"HADocumentation,omitempty" json:"HADocumentation,omitempty"`
HAActiveNode string `xml:"HAActiveNode,omitempty" json:"HAActiveNode,omitempty"`
HANodes *[]string `xml:"HANodes>item,omitempty" json:"HANodes>item,omitempty"`
}

type OSProcess struct {
Name string `xml:"name,omitempty" json:"name,omitempty"`
Description string `xml:"description,omitempty" json:"description,omitempty"`
Expand All @@ -91,6 +137,19 @@ type SAPInstance struct {
Dispstatus STATECOLOR `xml:"dispstatus,omitempty" json:"dispstatus,omitempty"`
}

type VersionInfo struct {
Filename string `xml:"Filename,omitempty" json:"Filename,omitempty"`
VersionInfo string `xml:"VersionInfo,omitempty" json:"VersionInfo,omitempty"`
Time string `xml:"Time,omitempty" json:"Time,omitempty"`
}

type HACheck struct {
State *HAVerificationState `xml:"state,omitempty" json:"state,omitempty"`
Category *HACheckCategory `xml:"category,omitempty" json:"category,omitempty"`
Description string `xml:"description,omitempty" json:"description,omitempty"`
Comment string `xml:"comment,omitempty" json:"comment,omitempty"`
}

type webService struct {
client *soap.Client
}
Expand Down Expand Up @@ -163,3 +222,39 @@ func (s *webService) GetSystemInstanceList() (*GetSystemInstanceListResponse, er

return response, nil
}

// GetVersionInfo returns a list version information for the most important files of the instance
func (s *webService) GetVersionInfo() (*GetVersionInfoResponse, error) {
request := &GetVersionInfo{}
response := &GetVersionInfoResponse{}
err := s.client.Call("''", request, response)
if err != nil {
return nil, err
}

return response, nil
}

// HACheckConfig checks high availability configurration and status of the system
func (s *webService) HACheckConfig() (*HACheckConfigResponse, error) {
request := &HACheckConfig{}
response := &HACheckConfigResponse{}
err := s.client.Call("''", request, &response)
if err != nil {
return nil, err
}

return response, nil
}

// HAGetFailoverConfig returns HA failover third party information
func (s *webService) HAGetFailoverConfig() (*HAGetFailoverConfigResponse, error) {
request := &HAGetFailoverConfig{}
response := &HAGetFailoverConfigResponse{}
err := s.client.Call("''", request, &response)
if err != nil {
return nil, err
}

return response, nil
}
1 change: 1 addition & 0 deletions internal/factsengine/gatherers/gatherer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func StandardGatherers() map[string]FactGatherer {
HostsFileGathererName: NewDefaultHostsFileGatherer(),
PackageVersionGathererName: NewDefaultPackageVersionGatherer(),
PasswdGathererName: NewDefaultPasswdGatherer(),
SapControlGathererName: NewDefaultSapControlGatherer(),
SapHostCtrlGathererName: NewDefaultSapHostCtrlGatherer(),
SapProfilesGathererName: NewDefaultSapProfilesGatherer(),
SaptuneGathererName: NewDefaultSaptuneGatherer(),
Expand Down
Loading

0 comments on commit f41d120

Please sign in to comment.