Skip to content

Commit

Permalink
[20170213]add gitignore and requirements.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-canux committed Feb 13, 2017
1 parent 0dd1e99 commit 6d62b51
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 97 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* linguist-language=Python
91 changes: 91 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
#htmlcov/
#.tox/
#.coverage
#.coverage.*
#.cache
#nosetests.xml
#coverage.xml
#*,cover
#.hypothesis/

# Translations
#*.mo
#*.pot

# Django stuff:
#*.log
#local_settings.py

# Flask stuff:
#instance/
#.webassets-cache

# Scrapy stuff:
#.scrapy

# Sphinx documentation
#docs/_build/

# PyBuilder
#target/

# Jupyter Notebook
#.ipynb_checkpoints

# pyenv
#.python-version

# celery beat schedule file
#celerybeat-schedule

# dotenv
#.env

# virtualenv
.venv
venv/
ENV/

# Spyder project settings
#.spyderproject

# Rope project settings
.ropeproject
13 changes: 7 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ Also you can pull request for your code.
TODO
-----

1. Compatible with Python3(2.0)
2. tivoli examples(1.7)
3. check_mk examples(1.6)
4. pymonitoringplugins/docs build with sphinx(1.5)
5. Thresholders need follow nagios rules(1.4)
6. snmp(1.3)
* vmware monitoring
* Compatible with Python3(2.0)
* tivoli examples(1.7)
* check_mk examples(1.6)
* pymonitoringplugins/docs build with sphinx(1.5)
* Thresholders need follow nagios rules(1.4)
* snmp(1.3)

=============
Documentation
Expand Down
39 changes: 20 additions & 19 deletions examples/Nagios/check_wmi_sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,25 +239,26 @@ def fileage_handle(self):

for file_dict in self.__file_list:
self.filename = file_dict.get('Name')
self.logger.debug("===== start to compare {} =====".format(self.filename))

self.file_datetime_string = file_dict.get('LastModified').split('.')[0]
self.file_datetime = datetime.datetime.strptime(self.file_datetime_string, '%Y%m%d%H%M%S')
self.logger.debug("file_datetime: {}".format(self.file_datetime))

self.current_datetime = self.__get_current_datetime()
self.logger.debug("current_datetime: {}".format(self.current_datetime))

self.__delta_datetime = self.current_datetime - self.file_datetime
self.logger.debug("delta_datetime: {}".format(self.__delta_datetime))
self.logger.debug("warn_datetime: {}".format(datetime.timedelta(minutes=self.args.warning)))
self.logger.debug("crit_datetime: {}".format(datetime.timedelta(minutes=self.args.critical)))
if self.__delta_datetime > datetime.timedelta(minutes=self.args.critical):
self.crit_file.append(self.filename)
elif self.__delta_datetime > datetime.timedelta(minutes=self.args.warning):
self.warn_file.append(self.filename)
else:
self.ok_file.append(self.filename)
if self.filename and self.filename != 'Name':
self.logger.debug("===== start to compare {} =====".format(self.filename))

self.file_datetime_string = file_dict.get('LastModified').split('.')[0]
self.file_datetime = datetime.datetime.strptime(self.file_datetime_string, '%Y%m%d%H%M%S')
self.logger.debug("file_datetime: {}".format(self.file_datetime))

self.current_datetime = self.__get_current_datetime()
self.logger.debug("current_datetime: {}".format(self.current_datetime))

self.__delta_datetime = self.current_datetime - self.file_datetime
self.logger.debug("delta_datetime: {}".format(self.__delta_datetime))
self.logger.debug("warn_datetime: {}".format(datetime.timedelta(minutes=self.args.warning)))
self.logger.debug("crit_datetime: {}".format(datetime.timedelta(minutes=self.args.critical)))
if self.__delta_datetime > datetime.timedelta(minutes=self.args.critical):
self.crit_file.append(self.filename)
elif self.__delta_datetime > datetime.timedelta(minutes=self.args.warning):
self.warn_file.append(self.filename)
else:
self.ok_file.append(self.filename)

# Compare the vlaue.
if self.crit_file:
Expand Down
39 changes: 20 additions & 19 deletions examples/Nagios/check_wmi_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,25 +239,26 @@ def fileage_handle(self):

for file_dict in self.__file_list:
self.filename = file_dict.get('Name')
self.logger.debug("===== start to compare {} =====".format(self.filename))

self.file_datetime_string = file_dict.get('LastModified').split('.')[0]
self.file_datetime = datetime.datetime.strptime(self.file_datetime_string, '%Y%m%d%H%M%S')
self.logger.debug("file_datetime: {}".format(self.file_datetime))

self.current_datetime = self.__get_current_datetime()
self.logger.debug("current_datetime: {}".format(self.current_datetime))

self.__delta_datetime = self.current_datetime - self.file_datetime
self.logger.debug("delta_datetime: {}".format(self.__delta_datetime))
self.logger.debug("warn_datetime: {}".format(datetime.timedelta(minutes=self.args.warning)))
self.logger.debug("crit_datetime: {}".format(datetime.timedelta(minutes=self.args.critical)))
if self.__delta_datetime > datetime.timedelta(minutes=self.args.critical):
self.crit_file.append(self.filename)
elif self.__delta_datetime > datetime.timedelta(minutes=self.args.warning):
self.warn_file.append(self.filename)
else:
self.ok_file.append(self.filename)
if self.filename and self.filename != 'Name':
self.logger.debug("===== start to compare {} =====".format(self.filename))

self.file_datetime_string = file_dict.get('LastModified').split('.')[0]
self.file_datetime = datetime.datetime.strptime(self.file_datetime_string, '%Y%m%d%H%M%S')
self.logger.debug("file_datetime: {}".format(self.file_datetime))

self.current_datetime = self.__get_current_datetime()
self.logger.debug("current_datetime: {}".format(self.current_datetime))

self.__delta_datetime = self.current_datetime - self.file_datetime
self.logger.debug("delta_datetime: {}".format(self.__delta_datetime))
self.logger.debug("warn_datetime: {}".format(datetime.timedelta(minutes=self.args.warning)))
self.logger.debug("crit_datetime: {}".format(datetime.timedelta(minutes=self.args.critical)))
if self.__delta_datetime > datetime.timedelta(minutes=self.args.critical):
self.crit_file.append(self.filename)
elif self.__delta_datetime > datetime.timedelta(minutes=self.args.warning):
self.warn_file.append(self.filename)
else:
self.ok_file.append(self.filename)

# Compare the vlaue.
if self.crit_file:
Expand Down
Binary file removed pymonitoringplugins/__init__.pyc
Binary file not shown.
Binary file removed pymonitoringplugins/ftp_ftplib.pyc
Binary file not shown.
17 changes: 14 additions & 3 deletions pymonitoringplugins/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Version: V1.0.0.0
Time: Thu 28 Jul 2016 03:23:45 PM CST
Description:
DESCRIPTION:
Test on nagios, naemon, icinga, shinken, centreon, opsview and sensu except check_mk.
[1.0.0.0] 20160728 init for basic function.
"""
Expand Down Expand Up @@ -88,6 +88,13 @@ def __define_options(self):
def define_sub_options(self):
"""Define options for monitoring plugins.
:param host: Monitoring Server IP address or Hostname.
:type host: string.
:param user: Monitoring Server User name.
:type user: string.
:param password: Monitoring Server User password.
:type password: string.
Rewrite your method and define your suparsers.
Use subparsers.add_parser to create sub options for one function.
"""
Expand Down Expand Up @@ -118,8 +125,12 @@ def __parse_options(self):
def output(self, substitute=None, long_output_limit=None):
"""Just for nagios output and tools based on nagios except check_mk.
Default longoutput show everything.
But you can use long_output_limit to limit the longoutput lines.
:param substitute: what you want to show in output.
:type substitute: dict.
:param long_output_limit: how many lines you want in output.
:type long_output_limit: int.
:return: return shortoutput + longoutput + perfdata.
:rtype: string.
"""
if not substitute:
substitute = {}
Expand Down
Binary file modified pymonitoringplugins/monitor.pyc
Binary file not shown.
51 changes: 26 additions & 25 deletions pymonitoringplugins/tests/test_wmi_sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
[1.0.0.0] 20160728 init for basic function.
Example:
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug filenumber -d 'C:' -r
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug filenumber -d 'C:' -p '\\' -f '%%' -e '%%' -r
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug filenumber -d 'C:' -p '\\Windows\\' -f '%%' -e '%%' -r
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug filenumber -d 'C:' -R
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug filenumber -d 'C:' -p '\\' -f '%%' -e '%%' -R
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug filenumber -d 'C:' -p '\\Windows\\' -f '%%' -e '%%' -R
Example:
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug fileage -d 'C:' -r
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug fileage -d 'C:' -p '\\' -f '%%' -e '%%' -r
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug fileage -d 'C:' -p '\\Windows\\' -f '%%' -e '%%' -r
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug fileage -d 'C:' -R
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug fileage -d 'C:' -p '\\' -f '%%' -e '%%' -R
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug fileage -d 'C:' -p '\\Windows\\' -f '%%' -e '%%' -R
Example:
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug sqlserverlocks -m LockTimeoutsPersec -w 0 -c 0
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug sqlserverlocks -m LockWaitsPersec -w 0 -c 0
Expand Down Expand Up @@ -254,25 +254,26 @@ def fileage_handle(self):

for file_dict in self.__file_list:
self.filename = file_dict.get('Name')
self.logger.debug("===== start to compare {} =====".format(self.filename))

self.file_datetime_string = file_dict.get('LastModified').split('.')[0]
self.file_datetime = datetime.datetime.strptime(self.file_datetime_string, '%Y%m%d%H%M%S')
self.logger.debug("file_datetime: {}".format(self.file_datetime))

self.current_datetime = self.__get_current_datetime()
self.logger.debug("current_datetime: {}".format(self.current_datetime))

self.__delta_datetime = self.current_datetime - self.file_datetime
self.logger.debug("delta_datetime: {}".format(self.__delta_datetime))
self.logger.debug("warn_datetime: {}".format(datetime.timedelta(minutes=self.args.warning)))
self.logger.debug("crit_datetime: {}".format(datetime.timedelta(minutes=self.args.critical)))
if self.__delta_datetime > datetime.timedelta(minutes=self.args.critical):
self.crit_file.append(self.filename)
elif self.__delta_datetime > datetime.timedelta(minutes=self.args.warning):
self.warn_file.append(self.filename)
else:
self.ok_file.append(self.filename)
if self.filename and self.filename != 'Name':
self.logger.debug("===== start to compare {} =====".format(self.filename))

self.file_datetime_string = file_dict.get('LastModified').split('.')[0]
self.file_datetime = datetime.datetime.strptime(self.file_datetime_string, '%Y%m%d%H%M%S')
self.logger.debug("file_datetime: {}".format(self.file_datetime))

self.current_datetime = self.__get_current_datetime()
self.logger.debug("current_datetime: {}".format(self.current_datetime))

self.__delta_datetime = self.current_datetime - self.file_datetime
self.logger.debug("delta_datetime: {}".format(self.__delta_datetime))
self.logger.debug("warn_datetime: {}".format(datetime.timedelta(minutes=self.args.warning)))
self.logger.debug("crit_datetime: {}".format(datetime.timedelta(minutes=self.args.critical)))
if self.__delta_datetime > datetime.timedelta(minutes=self.args.critical):
self.crit_file.append(self.filename)
elif self.__delta_datetime > datetime.timedelta(minutes=self.args.warning):
self.warn_file.append(self.filename)
else:
self.ok_file.append(self.filename)

# Compare the vlaue.
if self.crit_file:
Expand Down
51 changes: 26 additions & 25 deletions pymonitoringplugins/tests/test_wmi_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
Description:
[1.0.0.0] 20160728 init for basic function.
Example:
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug filenumber -d 'C:' -r
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug filenumber -d 'C:' -p '\\' -f '%%' -e '%%' -r
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug filenumber -d 'C:' -p '\\Windows\\' -f '%%' -e '%%' -r
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug filenumber -d 'C:' -R
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug filenumber -d 'C:' -p '\\' -f '%%' -e '%%' -R
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug filenumber -d 'C:' -p '\\Windows\\' -f '%%' -e '%%' -R
Example:
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug fileage -d 'C:' -r
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug fileage -d 'C:' -p '\\' -f '%%' -e '%%' -r
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug fileage -d 'C:' -p '\\Windows\\' -f '%%' -e '%%' -r
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug fileage -d 'C:' -R
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug fileage -d 'C:' -p '\\' -f '%%' -e '%%' -R
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug fileage -d 'C:' -p '\\Windows\\' -f '%%' -e '%%' -R
Example:
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug sqlserverlocks -m LockTimeoutsPersec -w 0 -c 0
check_wmi.py -H HOSTNAME -d [Domain] -u USER -p [password] --debug sqlserverlocks -m LockWaitsPersec -w 0 -c 0
Expand Down Expand Up @@ -253,25 +253,26 @@ def fileage_handle(self):

for file_dict in self.__file_list:
self.filename = file_dict.get('Name')
self.logger.debug("===== start to compare {} =====".format(self.filename))

self.file_datetime_string = file_dict.get('LastModified').split('.')[0]
self.file_datetime = datetime.datetime.strptime(self.file_datetime_string, '%Y%m%d%H%M%S')
self.logger.debug("file_datetime: {}".format(self.file_datetime))

self.current_datetime = self.__get_current_datetime()
self.logger.debug("current_datetime: {}".format(self.current_datetime))

self.__delta_datetime = self.current_datetime - self.file_datetime
self.logger.debug("delta_datetime: {}".format(self.__delta_datetime))
self.logger.debug("warn_datetime: {}".format(datetime.timedelta(minutes=self.args.warning)))
self.logger.debug("crit_datetime: {}".format(datetime.timedelta(minutes=self.args.critical)))
if self.__delta_datetime > datetime.timedelta(minutes=self.args.critical):
self.crit_file.append(self.filename)
elif self.__delta_datetime > datetime.timedelta(minutes=self.args.warning):
self.warn_file.append(self.filename)
else:
self.ok_file.append(self.filename)
if self.filename and self.filename != 'Name':
self.logger.debug("===== start to compare {} =====".format(self.filename))

self.file_datetime_string = file_dict.get('LastModified').split('.')[0]
self.file_datetime = datetime.datetime.strptime(self.file_datetime_string, '%Y%m%d%H%M%S')
self.logger.debug("file_datetime: {}".format(self.file_datetime))

self.current_datetime = self.__get_current_datetime()
self.logger.debug("current_datetime: {}".format(self.current_datetime))

self.__delta_datetime = self.current_datetime - self.file_datetime
self.logger.debug("delta_datetime: {}".format(self.__delta_datetime))
self.logger.debug("warn_datetime: {}".format(datetime.timedelta(minutes=self.args.warning)))
self.logger.debug("crit_datetime: {}".format(datetime.timedelta(minutes=self.args.critical)))
if self.__delta_datetime > datetime.timedelta(minutes=self.args.critical):
self.crit_file.append(self.filename)
elif self.__delta_datetime > datetime.timedelta(minutes=self.args.warning):
self.warn_file.append(self.filename)
else:
self.ok_file.append(self.filename)

# Compare the vlaue.
if self.crit_file:
Expand Down
21 changes: 21 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
appdirs==1.4.0
cffi==1.9.1
cryptography==1.7.2
enum34==1.1.6
idna==2.2
ipaddress==1.0.18
ntlm-auth==1.0.2
ordereddict==1.1
packaging==16.8
paramiko==2.1.1
pyasn1==0.2.2
pycparser==2.17
pymssql==2.1.3
PyMySQL==0.7.9
pyparsing==2.1.10
pywinrm==0.2.2
requests==2.13.0
requests-ntlm==1.0.0
sh==1.12.9
six==1.10.0
xmltodict==0.10.2

0 comments on commit 6d62b51

Please sign in to comment.