Skip to content

ManGravityR/WebMonitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebMonitor

Requirements

  • Python > 3.8 recommended

Notice:

  • All settings are stored in JSON format, so it's easy to exchange data using the API.
  • JSON file is individual for the instance you create, which allows you to configure different entry points.

Usage

  1. Import Package
  2. Create class prototype:
monitor = WebMonitor(pcf='WebMonitor')

Args:

  • pcf - Storage name for Class, default = 'WebMonitor'

Add host(s)

monitor.add('google.com')

Supported list format:

monitor.add(['example.org', 'yandex.com', 'bing.com'])

Return: hosts list


Check host(s)

If you use an empty method (without params), then will be checked all hosts in the config .pcf file and recorded in history.

Example:

print(monitor.check())

Check result

If you specified a list of hosts, they will be checked and recorded in history. Without adding to the configuration.

Example:

print(monitor.check('yahoo.com', 'ibm.com'))

Or supported list format:

print(monitor.check(['intel.com', 'ibm.com']))

Check result

Return: hosts list


Remove host(s)

If you use an empty method (without params), then will be removed all hosts in the config .pcf file. Before deleting, you will be prompted to delete. By default, pressing enter means consent to deletion.

Example:

monitor.remove()

If you specified a list of hosts, they will be checked and removed from configuration.

Example:

monitor.remove('google.com')

Or supported list format:

monitor.remove(['example.org', 'bing.com'])

Return: hosts list


Show hosts list from file as string

monitor.show()

Call: print hosts as strings

Return: hosts list


Show history checks

print(monitor.history())

If you need clear history:

print(monitor.history(clear=True))

History search terms supported:

  • id
  • date
  • host
  • status_code

Format parameters: [{field: value}, *multiply]

How use search conditions

Typical:

history = monitor.history(by=[{'date': '2020.12.05'}, {'host': 'google.com'}])

Or create conditions list with dict {filed: value} and pass in method, example:

conditions = [
    {'date': '2020.12.05'}, 
    {'host': 'google.com'}
]
history = monitor.history(by=conditions)
print(history)

Return: formatted table report


Dev tasks

  • Fix or define correct protocol for host (now used http)
  • Create Watcher (endless loop or timer)
  • Create notifications to Telegram bot (?)
  • Create notifications to Email (?)
  • Optimize code (?)

Please see the changelog for more extensive changes.


See how it works

Run WebMonitorTest.py