add Hostname helper in expr and templating (#2193)
This commit is contained in:
parent
71b7a594bd
commit
4ae41a363d
|
@ -1,6 +1,7 @@
|
||||||
package csplugin
|
package csplugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/exprhelpers"
|
"github.com/crowdsecurity/crowdsec/pkg/exprhelpers"
|
||||||
|
@ -20,6 +21,7 @@ var helpers = template.FuncMap{
|
||||||
return metaValues
|
return metaValues
|
||||||
},
|
},
|
||||||
"CrowdsecCTI": exprhelpers.CrowdsecCTI,
|
"CrowdsecCTI": exprhelpers.CrowdsecCTI,
|
||||||
|
"Hostname": os.Hostname,
|
||||||
}
|
}
|
||||||
|
|
||||||
func funcMap() template.FuncMap {
|
func funcMap() template.FuncMap {
|
||||||
|
|
|
@ -398,6 +398,13 @@ var exprFuncs = []exprCustomFunc{
|
||||||
new(func(string) string),
|
new(func(string) string),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Hostname",
|
||||||
|
function: Hostname,
|
||||||
|
signature: []interface{}{
|
||||||
|
new(func() (string, error)),
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
//go 1.20 "CutPrefix": strings.CutPrefix,
|
//go 1.20 "CutPrefix": strings.CutPrefix,
|
||||||
|
|
|
@ -595,3 +595,11 @@ func B64Decode(params ...any) (any, error) {
|
||||||
}
|
}
|
||||||
return string(decoded), nil
|
return string(decoded), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Hostname(params ...any) (any, error) {
|
||||||
|
hostname, err := os.Hostname()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return hostname, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue