collector module

class collector.Collector[source]

Bases: object

A class to collect, format and print information gathered from hosts.

json_indentation

The default is 4. It can be changed in the configuration.

Configure json indentation
---
defaults:
  report_types:
    - html
    - json:2
Type:

int

htmltop

html snippet for html report. See constants.Constants.HTML_TOP.

Type:

str

htmlbottom

html snippet for html report. See constants.Constants.HTML_BOTTOM.

Type:

str

collected_objects
Something like this depending on the configuration
[
        {
                "group": "awesomegroup",
                "host": "some-switch",
                "errors": [],
                "rc": 0,
                "output": {
                        "cmds_before": [
                                "ip name-server 8.8.8.8"
                        ],
                        "cmds_after": [
                                "ip name-server 9.9.9.9"
                        ]
                },
                "message": "ok",
                "config": {
                        "settings": {
                                "device_type": "cisco_ios",
                                "connection_timeout": 10,
                                "read_timeout": 10,
                                "silent": True,
                                "conf_cmds": [
                                        "no ip name-server 8.8.8.8",
                                        "ip name-server 9.9.9.9"
                                ],
                                "cmds_before": [
                                        "show run | include name-server"
                                ],
                                "cmds_after": [
                                        "show run | include name-server"
                                ],
                                "log_file": "~/.conquers/some-switch.log"
                        },
                        "credentials": {
                                "user": "admin",
                                "host": "some-switch",
                                "encrypted_pass": "********",
                                "pass": "********"
                        }
                }
        },
]
Type:

list

hosts_by_group
Something like this depending on the configuration
{
    "awesomegroup": [
        {
            "another-switch": {
                "errors": [],
                "rc": null,
                "message": "skipped",
                "config": {
                    "host": "another-switch",
                    "settings": {
                        "device_type": "cisco_ios",
                        "connection_timeout": 10,
                        "read_timeout": 10,
                        "silent": true
                    },
                    "credentials": false
                }
            }
        },
        {
            "some-switch": {
                "errors": [],
                "rc": 0,
                "output": {
                    "cmds_before": [
                        "ip name-server 8.8.8.8"
                    ],
                    "cmds_after": [
                        "ip name-server 9.9.9.9"
                    ]
                },
                "message": "ok",
                "config": {
                    "settings": {
                        "device_type": "cisco_ios",
                        "connection_timeout": 10,
                        "read_timeout": 10,
                        "silent": true,
                        "conf_cmds": [
                            "no ip name-server 8.8.8.8",
                            "ip name-server 9.9.9.9"
                        ],
                        "cmds_before": [
                            "show run | include name-server"
                        ],
                        "cmds_after": [
                            "show run | include name-server"
                        ],
                        "log_file": "~/.conquers/some-switch.log"
                    },
                    "credentials": {
                        "user": "admin",
                        "host": "some-switch",
                        "encrypted_pass": "********",
                        "pass": "********"
                    }
                }
            }
        }
    ],
    "anothergroup": [
        "..."
    ],
}
Type:

dict

add_to_collection(item) None[source]

Adds item to collected_objects

Parameters:

item (dict) – Object to add

hide_passwords(data) None[source]

Overrides password strings with * for console output.

Parameters:

data (dict) –

log_to_file(data) None[source]

If log_file is specified in the configuration, the output of commands sent to a swtich and information about the host are logged to this file.

log_to_report() None[source]

Logs a full report if configured in the configuration file. Three output format are possible:

  • html (fancy, recommended for humans)

  • yaml

  • json or json:<indentation>

print_complete_summary() None[source]

Print brief information about completed hosts in a table.

static print_error(string, **kwargs) None[source]

Print error to console in red.

static print_extra_info(string, **kwargs) None[source]

Prints additional information in grey.

static print_info(string, **kwargs) None[source]

Print to console in bright green.

static print_mild_info(string, **kwargs) None[source]

Print to console in normal green.

print_single_summary(data) None[source]

Print collected info in yaml format to the console. This can be silenced by setting silent to true in the configuration.

static print_warning(string, **kwargs) None[source]

Print a warning to console in purple.

exception collector.CollectorError[source]

Bases: Exception