feat: add trigger to allow retrieving resource properties on the fly

This commit is contained in:
Jose Diaz-Gonzalez
2019-04-08 11:31:18 -04:00
parent 243d5ecc43
commit c2898ec040
4 changed files with 49 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
package resource
import (
"errors"
"fmt"
"os"
"reflect"
@@ -66,6 +67,25 @@ func ReportSingleApp(appName, infoFlag string) {
common.LogFail(fmt.Sprintf("Invalid flag passed, valid flags: %s", strings.Join(strkeys, ", ")))
}
func GetResourceValue(appName string, procType string, resourceType string, prefix string) (string, error) {
resources, err := common.PropertyGetAll("resource", appName)
if err != nil {
return "", err
}
for key, value := range resources {
parts := strings.SplitN(strings.TrimPrefix(key, prefix), ".", 2)
if parts[0] != resourceType {
return "", err
}
if parts[1] == prefix {
return value, nil
}
}
return "", errors.New("No value found")
}
func times(str string, n int) (out string) {
for i := 0; i < n; i++ {
out += str