percona-monitoring-plugins icon indicating copy to clipboard operation
percona-monitoring-plugins copied to clipboard

pmp-check-mysql-deleted-files has no support for sudo

Open SineSwiper opened this issue 7 years ago • 4 comments

In the code for pmp-check-mysql-deleted-files, there is this bit:

     # If lsof exists, but you run it as non-root, you'll get a file with a
     # bunch of this stuff:
     # mysqld 15287 ... /proc/15287/cwd (readlink: Permission denied)
     # We have to detect this and return UNK.
     if grep -v -e denied -e COMMAND "${TEMP}" >/dev/null 2>&1; then
        local FILES=$(check_deleted_files "${TEMP}" "${OPT_TMPDIR}")
        NOTE="open but deleted files: ${FILES}"
        if [ "${FILES}" -a -z "${OPT_WARN}" ]; then
           NOTE="CRIT $NOTE"
        elif [ "${FILES}" ]; then
           NOTE="WARN $NOTE"
        else
           NOTE="OK no deleted files"
        fi
     else
        NOTE="UNK You must execute lsof with root privileges"
     fi

So, the script acknowledges that running lsof requires root privileges, enough to give the condition its own error message. But, what then? There is no switch to fix the lsof command to use sudo.

NRPE shouldn't ever be ran as root, so I'm not even considering that option. Although, it seems like this script is expected to run as root.

SineSwiper avatar Jan 16 '18 17:01 SineSwiper

The only other option is to set the UID bit on lsof but that enables it system-wide to all users.

netniV avatar Jan 16 '18 21:01 netniV

Or you could allow nrpe to run the script using sudo

bwitt avatar Jan 16 '18 21:01 bwitt

I have a patch to add a --sudo switch. Just need a round of internal code reviews and approvals first, and I'll share it.

SineSwiper avatar Jan 16 '18 22:01 SineSwiper

@SineSwiper thanks for the PR - please take a look at the comments and requested changes

cezmunsta avatar Jan 23 '19 09:01 cezmunsta