Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,9 @@ func getNginx() Nginx {
NginxClientVersion: Viper.GetInt(NginxClientVersion),
ConfigReloadMonitoringPeriod: Viper.GetDuration(NginxConfigReloadMonitoringPeriod),
TreatWarningsAsErrors: Viper.GetBool(NginxTreatWarningsAsErrors),
ApiTls: TLSConfig{
Ca: Viper.GetString(NginxApiTlsCa),
API: &NginxAPI{
URL: Viper.GetString(NginxApiURLKey),
TLS: TLSConfig{Ca: Viper.GetString(NginxApiTlsCa)},
},
}
}
Expand Down
15 changes: 12 additions & 3 deletions src/core/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ var (
NginxClientVersion: 7, // NGINX Plus R25+
ConfigReloadMonitoringPeriod: 10 * time.Second,
TreatWarningsAsErrors: false,
ApiTls: TLSConfig{
Ca: "",
API: &NginxAPI{
URL: "",
TLS: TLSConfig{
Ca: "",
},
},
},
ConfigDirs: "/etc/nginx:/usr/local/etc/nginx:/usr/share/nginx/modules:/etc/nms",
Expand Down Expand Up @@ -179,6 +182,7 @@ const (
NginxConfigReloadMonitoringPeriod = NginxKey + agent_config.KeyDelimiter + "config_reload_monitoring_period"
NginxTreatWarningsAsErrors = NginxKey + agent_config.KeyDelimiter + "treat_warnings_as_errors"
NginxApiTlsCa = NginxKey + agent_config.KeyDelimiter + "api_tls_ca"
NginxApiURLKey = NginxKey + agent_config.KeyDelimiter + "api_url"

// viper keys used in config
DataplaneKey = "dataplane"
Expand Down Expand Up @@ -325,10 +329,15 @@ var (
Usage: "On nginx -t, treat warnings as failures on configuration application.",
DefaultValue: Defaults.Nginx.TreatWarningsAsErrors,
},
&StringFlag{
Name: NginxApiURLKey,
Usage: "The NGINX Plus API URL.",
DefaultValue: Defaults.Nginx.API.URL,
},
&StringFlag{
Name: NginxApiTlsCa,
Usage: "The NGINX Plus CA certificate file location needed to call the NGINX Plus API if SSL is enabled.",
DefaultValue: Defaults.Nginx.ApiTls.Ca,
DefaultValue: Defaults.Nginx.API.TLS.Ca,
},
// Metrics
&DurationFlag{
Expand Down
7 changes: 6 additions & 1 deletion src/core/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ type Nginx struct {
NginxClientVersion int `mapstructure:"client_version" yaml:"-"`
ConfigReloadMonitoringPeriod time.Duration `mapstructure:"config_reload_monitoring_period" yaml:"-"`
TreatWarningsAsErrors bool `mapstructure:"treat_warnings_as_errors" yaml:"-"`
ApiTls TLSConfig `mapstructure:"api_tls" yaml:"-"`
API *NginxAPI `mapstructure:"api"`
}

type NginxAPI struct {
URL string `mapstructure:"url"`
TLS TLSConfig `mapstructure:"tls"`
}

type Dataplane struct {
Expand Down
4 changes: 2 additions & 2 deletions src/core/metrics/sources/nginx_plus.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func NewNginxPlus(baseDimensions *metrics.CommonDim, nginxNamespace, plusNamespa

client := http.DefaultClient

if conf.Nginx.ApiTls.Ca != "" && conf.IsFileAllowed(conf.Nginx.ApiTls.Ca) {
data, err := os.ReadFile(conf.Nginx.ApiTls.Ca)
if conf.Nginx.API != nil && conf.Nginx.API.TLS.Ca != "" && conf.IsFileAllowed(conf.Nginx.API.TLS.Ca) {
data, err := os.ReadFile(conf.Nginx.API.TLS.Ca)
if err != nil {
log.Errorf("Unable to collect NGINX Plus metrics. Failed to read NGINX CA certificate file: %v", err)
return nil
Expand Down
29 changes: 17 additions & 12 deletions src/core/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,25 @@ func (n *NginxBinaryType) GetNginxDetailsFromProcess(nginxProcess *Process) *pro
n.statusUrlMutex.RUnlock()

if urlsLength == 0 || nginxStatus == "" {
stubStatusApiUrl, err := sdk.GetStubStatusApiUrl(nginxDetailsFacade.ConfPath, n.config.IgnoreDirectives)
if err != nil {
log.Tracef("Unable to get Stub Status API URL from the configuration: NGINX OSS metrics will be unavailable for this system. please configure a Stub Status API to get NGINX OSS metrics: %v", err)
}
// If NGINX API URL is configured in agent config then use that istead of discovering the URL from the NGINX configuration
if n.config.Nginx.API != nil && n.config.Nginx.API.URL != "" {
nginxDetailsFacade.StatusUrl = n.config.Nginx.API.URL
} else {
stubStatusApiUrl, err := sdk.GetStubStatusApiUrl(nginxDetailsFacade.ConfPath, n.config.IgnoreDirectives)
if err != nil {
log.Tracef("Unable to get Stub Status API URL from the configuration: NGINX OSS metrics will be unavailable for this system. please configure a Stub Status API to get NGINX OSS metrics: %v", err)
}

nginxPlusApiUrl, err := sdk.GetNginxPlusApiUrl(nginxDetailsFacade.ConfPath, n.config.IgnoreDirectives)
if err != nil {
log.Tracef("Unable to get NGINX Plus API URL from the configuration: NGINX Plus metrics will be unavailable for this system. please configure a NGINX Plus API to get NGINX Plus metrics: %v", err)
}
nginxPlusApiUrl, err := sdk.GetNginxPlusApiUrl(nginxDetailsFacade.ConfPath, n.config.IgnoreDirectives)
if err != nil {
log.Tracef("Unable to get NGINX Plus API URL from the configuration: NGINX Plus metrics will be unavailable for this system. please configure a NGINX Plus API to get NGINX Plus metrics: %v", err)
}

if nginxDetailsFacade.Plus.Enabled {
nginxDetailsFacade.StatusUrl = nginxPlusApiUrl
} else {
nginxDetailsFacade.StatusUrl = stubStatusApiUrl
if nginxDetailsFacade.Plus.Enabled {
nginxDetailsFacade.StatusUrl = nginxPlusApiUrl
} else {
nginxDetailsFacade.StatusUrl = stubStatusApiUrl
}
}

n.statusUrlMutex.Lock()
Expand Down

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

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

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

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

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

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

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

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

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

Loading