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 option for configuration file #28

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 21 additions & 8 deletions README.md
Expand Up @@ -15,25 +15,36 @@ Binaries can be downloaded from [Github releases](https://github.com/mjavier2k/s

### Usage

```
./solidfire_exporter -u $SOLIDFIRE_USER -p $SOLIDFIRE_PASSWORD -e $SOLIDFIRE_ENDPOINT
Create *config.yaml* on the same directory as the solidfire_exporter binary

```yml
endpoint: https://192.168.1.2/json-rpc/11.3
listenPort: 9987
insecure: true
timeout: 30
username: solidfire-username
password: solidfire-password
```

```
Usage of solidfire-exporter:
Start Netapp Solidfire exporter

```bash
./solidfire_exporter


-l, --listenPort int Port for the exporter to listen on. May also be set by environment variable SOLIDFIRE_PORT. (default 9987)
-u, --username string User with which to authenticate to the Solidfire API. May also be set by environment variable SOLIDFIRE_USER. (default "my_solidfire_user")
-p, --password string Password with which to authenticate to the Solidfire API. May also be set by environment variable SOLIDFIRE_PASS. (default "my_solidfire_password")
-e, --endpoint string Endpoint for the Solidfire API. May also be set by environment variable SOLIDFIRE_RPC_ENDPOINT. (default "https://192.168.1.2/json-rpc/11.3")
-i, --insecure Whether to disable TLS validation when calling the Solidfire API. May also be set by environment variable INSECURE_SKIP_VERIFY.
-t, --timeout int HTTP Client timeout (in seconds) per call to Solidfire API. (default 30)
-c, --config string Specify default configuration file. (default: config.yaml)
```


__NOTE__: The account for __SOLIDFIRE_USER__ must have administrator access to the solidfire cluster so that QOS data will show up.

### Prometheus Configuration

```
```yml
- job_name: solidfire_exporter
honor_timestamps: true
scrape_interval: 30s
Expand All @@ -53,7 +64,7 @@ __NOTE__: The account for __SOLIDFIRE_USER__ must have administrator access to t

Create an file with the environment variables set and pass it to docker run.

```
```bash
docker run --env-file=.env_file --rm -p 8080:8080 mjavier/solidfire-exporter:latest
```

Expand All @@ -67,7 +78,9 @@ TO DO


### Contributing

We welcome any contributions. Please fork the project on GitHub and open Pull Requests for any proposed changes.

### License

Code is licensed under the Apache License 2.0.
26 changes: 20 additions & 6 deletions cmd/solidfire-exporter/main.go
Expand Up @@ -21,12 +21,12 @@ var (

func init() {
flag.CommandLine.SortFlags = false

flag.IntP(solidfire.ListenPortFlag, "l", 9987, fmt.Sprintf("Port for the exporter to listen on. May also be set by environment variable %v.", solidfire.ListenPortFlagEnv))
flag.StringP(solidfire.UsernameFlag, "u", "my_solidfire_user", fmt.Sprintf("User with which to authenticate to the Solidfire API. May also be set by environment variable %v.", solidfire.UsernameFlagEnv))
flag.StringP(solidfire.PasswordFlag, "p", "my_solidfire_password", fmt.Sprintf("Password with which to authenticate to the Solidfire API. May also be set by environment variable %v.", solidfire.PasswordFlagEnv))
flag.StringP(solidfire.EndpointFlag, "e", "https://192.168.1.2/json-rpc/11.3", fmt.Sprintf("Endpoint for the Solidfire API. May also be set by environment variable %v.", solidfire.EndpointFlagEnv))
flag.BoolP(solidfire.InsecureSSLFlag, "i", false, fmt.Sprintf("Whether to disable TLS validation when calling the Solidfire API. May also be set by environment variable %v.", solidfire.InsecureSSLFlagEnv))
flag.Int64P(solidfire.HTTPClientTimeoutFlag, "t", 30, fmt.Sprintf("HTTP Client timeout (in seconds) per call to Solidfire API."))
flag.StringP(solidfire.ConfigFileFlag, "c", "config", fmt.Sprintf("Specify configuration file."))
flag.Parse()

// PORT environment variable takes precedence in order to be backwards-compatible
Expand All @@ -36,12 +36,26 @@ func init() {
} else {
viper.BindEnv(solidfire.ListenPortFlag, solidfire.ListenPortFlagEnv)
}

viper.BindEnv(solidfire.UsernameFlag, solidfire.UsernameFlagEnv)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove these here, can we still pass username/password through an environment variable?
As I recall, we want to support username and password via an Environment variable or config file, but want to drop support for having them as command-line flags.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. thats what we want here. going to update this.

viper.BindEnv(solidfire.PasswordFlag, solidfire.PasswordFlagEnv)
viper.BindEnv(solidfire.EndpointFlag, solidfire.EndpointFlagEnv)
viper.BindEnv(solidfire.InsecureSSLFlag, solidfire.InsecureSSLFlagEnv)
viper.BindPFlags(flag.CommandLine)

// load default values if config file is present
// Environment variables and parameter flags takes precedence to config file
viper.SetConfigName(viper.GetString(solidfire.ConfigFileFlag))
viper.SetConfigType("yaml")
viper.AddConfigPath(".")

if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok == false {
panic(err)
}
log.Infof("No config file found.")
} else {
// Parameter takes precedence to ENV
// ENV takes precedence to config file
log.Infof("Found configuration file on %v ", viper.GetViper().ConfigFileUsed())
log.Warningf("Values on this configuration file can be overriden by ENV or Parameter flags.")
}
}
func main() {
log.Infof("Version: %v", sha1ver)
Expand Down
6 changes: 6 additions & 0 deletions config.yaml
@@ -0,0 +1,6 @@
endpoint: https://192.168.1.2/json-rpc/11.3
listenPort: 9987
insecure: true
http_client_timeout: 30
username: solidfire-username-config
password: solidfire-password-config
3 changes: 1 addition & 2 deletions pkg/solidfire/types.go
Expand Up @@ -12,9 +12,8 @@ var (
EndpointFlag = "endpoint"
InsecureSSLFlag = "insecure"
HTTPClientTimeoutFlag = "timeout"
ConfigFileFlag = "config.yaml"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the flag name not the flag's default value.

You probably meant this to be as such:

Suggested change
ConfigFileFlag = "config.yaml"
ConfigFileFlag = "config"

ListenPortFlagEnv = "SOLIDFIRE_PORT"
UsernameFlagEnv = "SOLIDFIRE_USER"
PasswordFlagEnv = "SOLIDFIRE_PASS"
EndpointFlagEnv = "SOLIDFIRE_RPC_ENDPOINT"
InsecureSSLFlagEnv = "INSECURE_SKIP_VERIFY"
)
Expand Down