check_users sample plugin
=========================

Invocation
----------

The check_users plugin follows is usually invoked from the command line. To
facilitate testing, we import it as Python module::

>>> from check_users import UsersCheck

Invoking check_users with the `-h` option gives the usual help message::

>>> import nagiosplugin
>>> c = nagiosplugin.Controller(UsersCheck, ['-h'])
>>> print c.format()
Usage: ...
Check number of users logged into the system.
...


Basic plugin usage
------------------

To demonstrate the plugin, we fake the `who` command with a home grown
version that returns always 5 users::

>>> import os
>>> import os.path
>>> import tempfile
>>> bin_dir = tempfile.mkdtemp()
>>> who_path = os.path.join(bin_dir, 'who')
>>> who = file(who_path, 'w')
>>> who.write("""\
... #!/bin/sh
... echo "foo bar baz qux quux"
... echo "# users=5"
... """)
>>> who.close()
>>> os.chmod(who_path, 0775)

Invoking `check_users` without parameters, it reports the current number of
users::

>>> c = nagiosplugin.Controller(UsersCheck, ['--who', who_path]).run()
>>> print c.format()
USERS OK - 5 users | users=5;;;0

Warning and critical thresholds may be specified as usual. For instance, 
`-w` sets the warning range::

>>> c = nagiosplugin.Controller(
...     UsersCheck, ['-w', '1:3', '--who', who_path]).run()
>>> print c.format()
USERS WARNING - users value 5 exceeds warning range 1:3 | users=5;1:3;;0


>>> import shutil
>>> shutil.rmtree(bin_dir)
