AWSIoTDeviceDefenderAgentSDK¶
AWSIoTDeviceDefenderAgentSDK.agent¶
-
class
AWSIoTDeviceDefenderAgentSDK.agent.
IoTClientWrapper
(endpoint, root_ca_path, certificate_path, private_key_path, client_id)¶ Bases:
object
Wrapper around the AWS Iot Python SDK.
Sets common parameters based on the AWS Iot Python SDK’s Basic PubSub sample.
-
publish
(publish_to_topic, payload)¶ Publish to MQTT
-
subscribe
(subscribe_to_topic, callback)¶ Subscribe to MQTT
-
connect
()¶ Connect to AWS IoT
-
-
AWSIoTDeviceDefenderAgentSDK.agent.
parse_args
()¶ Setup Commandline Argument Parsing
-
AWSIoTDeviceDefenderAgentSDK.agent.
custom_callback
(self, userdata, message)¶
AWSIoTDeviceDefenderAgentSDK.collector¶
-
class
AWSIoTDeviceDefenderAgentSDK.collector.
Collector
(short_metrics_names=False)¶ Bases:
object
Reads system information and populates a metrics object.
This implementation utilizes psutil to make parsing metrics easier and more cross-platform.
Parameters: short_metrics_names (bool) – Toggle short object tags in output metrics. -
listening_ports
(metrics)¶ Iterate over all inet connections in the LISTEN state and extract port and interface.
-
static
network_stats
(metrics)¶
-
static
network_connections
(metrics)¶
-
collect_metrics
()¶ Sample system metrics and populate a metrics object suitable for publishing to Device Defender.
-
AWSIoTDeviceDefenderAgentSDK.metrics¶
-
class
AWSIoTDeviceDefenderAgentSDK.metrics.
Metrics
(short_names=False, last_metric=None)¶ Bases:
object
A collection of system metric values, providing facilities for output in a Device Defender compliant format.
- Features:
Serialization Format: Metrics can be exported in either cbor or JSON format.
Delta metrics: if the class is initialized with a existing metrics object, for certain metrics, the difference between the old an current metric value will calculated and stored.
Selectable metric tags: allow for verbose metrics tags, for easier debugging, or short memonic tags, reducing the amount data transmitted and stored in memory.
Initialize a new metrics object.
Parameters: - short_names (bool) – Toggle short object tags in output metrics.
- last_metric (Metrics object) – Metric object used for delta metric calculation.
-
network_stats
¶ Retrieve network TCP and UDP stats aggregated across all interfaces.
-
listening_ports
(protocol)¶
-
add_listening_ports
(protocol, ports)¶ Add a sets of listening ports for a particular protocol.
Parameters: - protocol (string) – TCP or UDP, all others invalid and will not be added
- ports (list) – List of Dictionaries, each dictionary should have a “port” and optionally an “interface” key. Example Dictionary: {‘port’: 80, ‘interface’: ‘eth0’}
-
add_network_stats
(bytes_in, packets_in, bytes_out, packets_out)¶ Add cumulative network stats across all network interfaces. If a previous metrics object was supplied,attempts to calculate and store delta metric.
Parameters:
-
add_network_connection
(remote_addr, remote_port, interface, local_port)¶ Add network connection details.
Parameters:
-
network_connections
¶
-
to_json_string
(pretty_print=False)¶ Convert the metrics to a json string suitable for AWS IoT Device Defender.
Parameters: pretty_print (bool) – Set to true if you would like json to be formatted in a more human-friendly format.
-
to_cbor
()¶ Returns a cbor serialized metrics object.