-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
466733f
commit 43c5589
Showing
3 changed files
with
93 additions
and
49 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package monitoring | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type Config struct { | ||
CPU bool | ||
Disk bool | ||
Host bool | ||
Memory bool | ||
} | ||
|
||
func AllConfig() Config { | ||
return Config{CPU: true, Disk: true, Host: true, Memory: true} | ||
} | ||
|
||
func NoneConfig() Config { | ||
return Config{CPU: false, Disk: false, Host: false, Memory: false} | ||
} | ||
|
||
func ToConfig(data string) (Config, error) { | ||
// We currently only support a single value for this field. | ||
switch strings.ToLower(data) { | ||
case "none": | ||
return NoneConfig(), nil | ||
case "all": | ||
return AllConfig(), nil | ||
case "memory": | ||
return Config{Memory: true}, nil | ||
} | ||
|
||
return Config{}, fmt.Errorf("invalid monitoring type: %v", data) | ||
} | ||
|
||
// Verifies that each monitoring component enabled by spec is also enabled by policy. | ||
func CheckCompliance(policy Config, spec Config) error { | ||
invalidConfigs := []string{} | ||
|
||
if !policy.CPU && spec.CPU { | ||
invalidConfigs = append(invalidConfigs, "CPU") | ||
} | ||
|
||
if !policy.Disk && spec.Disk { | ||
invalidConfigs = append(invalidConfigs, "DISK") | ||
} | ||
|
||
if !policy.Host && spec.Host { | ||
invalidConfigs = append(invalidConfigs, "HOST") | ||
} | ||
|
||
if !policy.Memory && spec.Memory { | ||
invalidConfigs = append(invalidConfigs, "MEMORY") | ||
} | ||
|
||
if len(invalidConfigs) > 0 { | ||
return fmt.Errorf("the following monitoring types were enabled, but disallowed by launch policy: %v", invalidConfigs) | ||
} | ||
|
||
return 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
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