feat(inputs.win_services): add exclude filter (#10144)
Co-authored-by: Tomas Mikenda <tomas.mikenda@tieto.com>
This commit is contained in:
parent
cd0a7cd52f
commit
ba8c29acb0
|
|
@ -4,25 +4,27 @@ Reports information about Windows service status.
|
|||
|
||||
Monitoring some services may require running Telegraf with administrator privileges.
|
||||
|
||||
### Configuration:
|
||||
## Configuration
|
||||
|
||||
```toml
|
||||
[[inputs.win_services]]
|
||||
## Names of the services to monitor. Leave empty to monitor all the available services on the host. Globs accepted.
|
||||
## Names of the services to monitor. Leave empty to monitor all the available services on the host. Globs accepted. Case sensitive.
|
||||
service_names = [
|
||||
"LanmanServer",
|
||||
"TermService",
|
||||
"Win*",
|
||||
]
|
||||
excluded_service_names = ['WinRM'] # optional, list of service names to exclude
|
||||
```
|
||||
|
||||
### Measurements & Fields:
|
||||
### Measurements & Fields
|
||||
|
||||
- win_services
|
||||
- state : integer
|
||||
- startup_mode : integer
|
||||
- state : integer
|
||||
- startup_mode : integer
|
||||
|
||||
The `state` field can have the following values:
|
||||
|
||||
- 1 - stopped
|
||||
- 2 - start pending
|
||||
- 3 - stop pending
|
||||
|
|
@ -32,30 +34,33 @@ The `state` field can have the following values:
|
|||
- 7 - paused
|
||||
|
||||
The `startup_mode` field can have the following values:
|
||||
|
||||
- 0 - boot start
|
||||
- 1 - system start
|
||||
- 2 - auto start
|
||||
- 3 - demand start
|
||||
- 4 - disabled
|
||||
|
||||
### Tags:
|
||||
### Tags
|
||||
|
||||
- All measurements have the following tags:
|
||||
- service_name
|
||||
- display_name
|
||||
- service_name
|
||||
- display_name
|
||||
|
||||
### Example Output:
|
||||
```
|
||||
### Example Output
|
||||
|
||||
```shell
|
||||
win_services,host=WIN2008R2H401,display_name=Server,service_name=LanmanServer state=4i,startup_mode=2i 1500040669000000000
|
||||
win_services,display_name=Remote\ Desktop\ Services,service_name=TermService,host=WIN2008R2H401 state=1i,startup_mode=3i 1500040669000000000
|
||||
```
|
||||
|
||||
### TICK Scripts
|
||||
|
||||
A sample TICK script for a notification about a not running service.
|
||||
It sends a notification whenever any service changes its state to be not _running_ and when it changes that state back to _running_.
|
||||
The notification is sent via an HTTP POST call.
|
||||
|
||||
```
|
||||
```shell
|
||||
stream
|
||||
|from()
|
||||
.database('telegraf')
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ var sampleConfig = `
|
|||
"TermService",
|
||||
"Win*",
|
||||
]
|
||||
#excluded_service_names = [] # optional, list of service names to exclude
|
||||
`
|
||||
|
||||
var description = "Input plugin to report Windows services info."
|
||||
|
|
@ -94,8 +95,9 @@ var description = "Input plugin to report Windows services info."
|
|||
type WinServices struct {
|
||||
Log telegraf.Logger
|
||||
|
||||
ServiceNames []string `toml:"service_names"`
|
||||
mgrProvider ManagerProvider
|
||||
ServiceNames []string `toml:"service_names"`
|
||||
ServiceNamesExcluded []string `toml:"excluded_service_names"`
|
||||
mgrProvider ManagerProvider
|
||||
|
||||
servicesFilter filter.Filter
|
||||
}
|
||||
|
|
@ -109,7 +111,7 @@ type ServiceInfo struct {
|
|||
|
||||
func (m *WinServices) Init() error {
|
||||
var err error
|
||||
m.servicesFilter, err = filter.NewIncludeExcludeFilter(m.ServiceNames, nil)
|
||||
m.servicesFilter, err = filter.NewIncludeExcludeFilter(m.ServiceNames, m.ServiceNamesExcluded)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -225,3 +225,24 @@ func TestGatherContainsTag(t *testing.T) {
|
|||
acc1.AssertContainsTaggedFields(t, "win_services", fields, tags)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExcludingNamesTag(t *testing.T) {
|
||||
winServices := &WinServices{
|
||||
Log: testutil.Logger{},
|
||||
ServiceNamesExcluded: []string{"Service*"},
|
||||
mgrProvider: &FakeMgProvider{testSimpleData[0]},
|
||||
}
|
||||
winServices.Init()
|
||||
var acc1 testutil.Accumulator
|
||||
require.NoError(t, winServices.Gather(&acc1))
|
||||
|
||||
for _, s := range testSimpleData[0].services {
|
||||
fields := make(map[string]interface{})
|
||||
tags := make(map[string]string)
|
||||
fields["state"] = int(s.state)
|
||||
fields["startup_mode"] = int(s.startUpMode)
|
||||
tags["service_name"] = s.serviceName
|
||||
tags["display_name"] = s.displayName
|
||||
acc1.AssertDoesNotContainsTaggedFields(t, "win_services", fields, tags)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue