uptime_report package

Submodules

uptime_report.backend_utils module

uptime_report.backend_utils.group_by_range(it, pred, keyfunc=None)

Return contiguous ranges of items satisfying a predicate.

uptime_report.backend_utils.offset_iter

Call a method with limit/offset arguments until exhausted.

Given a callable that accepts limit/offset keyword arguments and returns an iterable, call the method repeatedly until less than limit items are returned, yielding each item.

uptime_report.cli module

Uptime report CLI.

This module contains all CLI entrypoints. Command line argument parsing and execution is implemented via clize.

Examples:

$ python -m uptime_report.cli --version
class uptime_report.cli.Format

Bases: enum.Enum

Enumeration of existing output format types.

class uptime_report.cli.TimeUnits

Bases: enum.Enum

Enumeration of time division abbreviations.

minutes

strm

hours

strh

days

strd

months

strmo

years

stry

uptime_report.cli.backends()

Print supported backends.

uptime_report.cli.get_log_level(level)

Convert a value to a log level.

Converts a case-insensitive log level name to the corresponding integer value from Python’s logging package.

Example

>>> assert logging.DEBUG == get_log_level('debug')
Parameters:level (str) – the value to convert
Returns:a log level from the logging package.
Return type:int
Raises:clize.errors.CliValueError – if the value cannot be converted.
uptime_report.cli.get_time(value, now=None)

Convert a parameter to a timestamp.

Based on the passed value create a timestamp that represents the value. Both absolute and relative forms are supported.

Example

>>> get_time('2017-06-03')
1496448000
>>> now = arrow.utcnow().replace(microsecond=0).timestamp
>>> get_time('+2d') == now + 2*60*60*24
True

Valid time units for relative values are described in TimeUnits. If a time unit is not provided the default is TimeUnits.days.

Additionally, for relative values, the current time can be specified by passing an Arrow instance as the now argument.

Example

>>> today = get_time('2017-06-03')
>>> get_time('+1d', arrow.get(today))
1496534400
Parameters:
  • value (str) – the value to convert
  • now (Arrow, optional) – the base time to use for relative values.
Returns:

a timestamp

Return type:

int

Raises:

clize.errors.CliValueError – if the value cannot be converted.

uptime_report.cli.main(**kwargs)

Run the CLI application.

uptime_report.cli.outages

List outages.

uptime_report.cli.uptime

Do the uptime reporting stuff.

uptime_report.cli.version()

Get the version of this program.

uptime_report.config module

uptime_report.config.write_config

Write out a sample config file. Use ‘-‘ for stdout.

Parameters:output – the path to the file to write.

uptime_report.outage module

Uptime report outages.

This module contains generic code for processing outages.

class uptime_report.outage.Outage(start, finish, before=None, after=None, meta=NOTHING)

Bases: object

An outage.

start

Arrow – the start time of the outage period.

finish

Arrow – the ending time of the outage period.

before

Arrow, optional – last time check was ok, if available.

after

Arrow, optional – next time check was ok, if available.

meta

(dict, optinal): arbitrary metadata about this outage.

classmethod fields()

Return the field names for this class.

Example

>>> Outage.fields()
['start', 'finish', 'before', 'after', 'meta']
Returns:a list of names as (str) instances.
Return type:list
for_json()

Return a representation of this object as a dict.

Example

>>> t = arrow.utcnow()
>>> Outage(t, t).for_json() == {
...    "start": t,
...    "finish": t,
...    "before": None,
...    "after": None,
...    "meta": {}
... }
True
Returns:a list of names as (str) instances.
Return type:list
uptime_report.outage.filter_outage_len(outages, minlen=0)

Filter-out outages that have a small duration.

Parameters:
  • outages (list) – list of Outage objects
  • minlen (int) – the minimum amount of seconds that the outage duration must have
Yields:

Outage – the next outage from the list that has the minimum duration.

Example

>>> outages = [Outage(start=1, finish=5), Outage(start=2, finish=3)]
>>> [o.start.timestamp for o in filter_outage_len(outages, minlen=2)]
[1]
uptime_report.outage.merge_outages(outages, overlap=0)

Merge a list of Outage objects.

uptime_report.outage.write_outages_csv(fhandle, outages)

Write a list of outages to a file as CSV.

Example

>>> from six import StringIO
>>> s = StringIO()
>>> t = arrow.get(0)
>>> write_outages_csv(s, [Outage(t, t)])
>>> s.getvalue()
'start,finish,before,after,meta\r\n1970-01-01T00:00:00+00:00,1970-01-01T00:00:00+00:00,,,{}\r\n'
Parameters:

Module contents

Pingdom Uptime Report - Generate uptime reports using the Pingdom API.