nrpe.Check._locate_cmd incorrectly parses check_cmd

Bug #1829496 reported by Alvaro Uria
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Charm Helpers
New
Undecided
Unassigned

Bug Description

if check_cmd is of the type:
check_http -I 127.0.0.1 -p 8193 -u / -s 'OpenStack Exporter'

_locate_cmd will parse it as:
/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -p 8193 -u / -s OpenStack Exporter

We want to preserve quotes when they exist, so as to get:
/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -p 8193 -u / -s 'OpenStack Exporter'

Fix is:

- command += " " + " ".join(parts[1:])
+ command += " " + " ".join(shlex.quote(part) for part in parts[1:])

Revision history for this message
Alvaro Uria (aluria) wrote :
Revision history for this message
Alvaro Uria (aluria) wrote :

shlex.quote is not supported in py2. A different approach will be needed.

Revision history for this message
Alvaro Uria (aluria) wrote :

Possibly replicate the shlex.quote code from py3 in the nrpe.py module:
"""
_find_unsafe = re.compile(r'[^\w@%+=:,./-]', re.ASCII).search

def quote(s):
    """Return a shell-escaped version of the string *s*."""
    if not s:
        return "''"
    if _find_unsafe(s) is None:
        return s

    # use single quotes, and put single quotes into double quotes
    # the string $'b is then quoted as '$'"'"'b'
    return "'" + s.replace("'", "'\"'\"'") + "'"
"""

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.