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