Skip to content

FEATURE REQUEST: check_service (windows) white spaces, quotes and dot notation #400

Description

@Gent00157

Is your feature request related to a problem? Please describe.
I have a "little" problem with check_service on windows. When checked service has white spaces in name (both service and display name), then perf data/metrics names are single quoted with white spaces, which makes problem in my setup (nagios + graphite/carbon backend).

example:
(note that service and display name are both "NetBackup Client Service", no way to avoid white spaces)

C:\Program Files\snclient>snclient.exe  run check_service service="NetBackup Client Service"
OK - All 1 service(s) are ok. |'NetBackup Client Service'=4 'NetBackup Client Service rss'=22560768B;;;0 'NetBackup Client Service vss'=5922816B;;;0 'NetBackup Client Service cpu'=0%;;;0

Another problem is that metric names (rss,vms, etc...) are present in quotes but graphite/carbon uses dot notation/separator for metric names, so I'd like performance data reformatted as you can see bellow.

I suggest add 3 extra config options to check_service:

  • servicename_whitespace_char = "_" # will replace all whitespaces chars in service names (result in svc_name)
  • graphite_dot_notation = true # will add separator for metrics (results in svcname.rss, svcname.vss, etc...)
  • servicename_state_suffix = ".state" # add suffix for service state (results in svcname.state=X)

This is just a suggestion, I can live without it as I use powershell wrapper script mentioned bellow and have not seen anybody care about it - I can send PR if considered as useful feature.

Describe the solution you'd like
I'd like performance output from check_service like ( 1/ white space are replace by underscore, 2/ metrics separated by dot and 3/ service state is reported by separate "state" metric ):

OK - All 1 service(s) are ok. | NetBackup_Client_Service.state=4 NetBackup_Client_Service.rss=22560768B;;;0 NetBackup_Client_Service.vms=5922816B;;;0 NetBackup_Client_Service.cpu=0%;;;0

Describe alternatives you've considered
I am using powershell wrapper for now, which reformat check_service output:

$SNClient = "C:\Program Files\snclient\snclient.exe"

$replChars = " " # replace chars
$repl2Char = "_" # what char to replace
$removeChars = "'"

# run orig command
$output = & $SNClient run $args
$exitCode = $LASTEXITCODE

$msg,$perf = $output.split("|")

# remove single quote, replace white spaces
$p = ""
if ($perf) {
    [Regex]::Matches($perf,"'[^']+'=[^ ]+") | ForEach-Object {
        $pn = $_ -replace $replChars,$repl2Char # replace chars
        $pn = $pn -replace $removeChars,"" # remove chars
        # append state node
        if ($pn -notmatch "_(rss|vms|cpu)=") {
            $pn = $pn -replace "=",".state="
        }
        $pn = $pn -replace "_(rss|vms|cpu)=",".`${1}="
        $p += "$pn "
    }
}

echo "$msg|$p"
exit $exitCode

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions