├── CPU-Edge-Node-Telemetry-Data.png ├── node-policy.json ├── deployment-policy-mqtt.json ├── Dockerfile ├── service.json ├── README.md ├── messaging.pem ├── Makefile ├── psutil2mqtt.py └── LICENSE /CPU-Edge-Node-Telemetry-Data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/johnwalicki/openhorizon-edge-cpu-mqtt/main/CPU-Edge-Node-Telemetry-Data.png -------------------------------------------------------------------------------- /node-policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { "name": "think", "value": "$DOCKERHUB_ID" } 4 | ], 5 | "constraints": [ 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /deployment-policy-mqtt.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "$SERVICE_NAME Deployment Policy", 3 | "description": "CPU Telemetry Open Horizon Deployment Policy", 4 | "service": { 5 | "name": "$SERVICE_NAME", 6 | "org": "$HZN_ORG_ID", 7 | "arch": "$ARCH", 8 | "serviceVersions": [ 9 | { 10 | "version": "$SERVICE_VERSION", 11 | "priority":{} 12 | } 13 | ] 14 | }, 15 | "properties": [], 16 | "constraints": [ 17 | "think == $DOCKERHUB_ID" 18 | ], 19 | "userInput": [ 20 | { 21 | "serviceOrgid": "$HZN_ORG_ID", 22 | "serviceUrl": "$SERVICE_NAME", 23 | "serviceVersionRange": "[$SERVICE_VERSION]", 24 | "inputs": [] 25 | } 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.11 as build 2 | LABEL stage=builder 3 | 4 | RUN apt update && apt install -y --no-install-recommends gcc build-essential python3-dev 5 | 6 | RUN mkdir -p /app 7 | 8 | RUN python -m venv /app 9 | # Make sure we use the virtualenv: 10 | ENV PATH="/app/bin:$PATH" 11 | RUN pip install --trusted-host=pypi.python.org \ 12 | --trusted-host=pypi.org \ 13 | --trusted-host=files.pythonhosted.org \ 14 | psutil paho-mqtt 15 | 16 | COPY messaging.pem /app/ 17 | COPY psutil2mqtt.py /app/ 18 | 19 | ## Deployment container 20 | FROM python:3.11-slim 21 | 22 | RUN mkdir -p /app 23 | ENV PATH="/app/bin:$PATH" 24 | COPY --from=build /app /app 25 | WORKDIR /app 26 | CMD [ "python3", "-u", "psutil2mqtt.py"] 27 | -------------------------------------------------------------------------------- /service.json: -------------------------------------------------------------------------------- 1 | { 2 | "org": "$HZN_ORG_ID", 3 | "label": "$SERVICE_NAME for $ARCH", 4 | "url": "$SERVICE_NAME", 5 | "version": "$SERVICE_VERSION", 6 | "arch": "$ARCH", 7 | "public": true, 8 | "sharable": "singleton", 9 | "requiredServices": [], 10 | "userInput": [ 11 | { 12 | "name": "MQTT_ORGID", 13 | "label": "Watson IoT Platform Org", 14 | "type": "string", 15 | "defaultValue": "" 16 | }, 17 | { 18 | "name": "MQTT_DEVICETYPE", 19 | "label": "Watson IoT DeviceType", 20 | "type": "string", 21 | "defaultValue": "ThinkEdge" 22 | }, 23 | { 24 | "name": "MQTT_DEVICEID", 25 | "label": "Watson IoT Device", 26 | "type": "string", 27 | "defaultValue": "instructor" 28 | }, 29 | { 30 | "name": "MQTT_DEVICETOKEN", 31 | "label": "Watson IoT Device Token", 32 | "type": "string", 33 | "defaultValue": "Think2022" 34 | } 35 | ], 36 | "deployment": { 37 | "services": { 38 | "$SERVICE_NAME": { 39 | "image": "$SERVICE_CONTAINER" 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IBM Edge Application Manager CPU Output to Watson IoT Platform 2 | 3 | This repository builds a Docker containerized workload that can be deployed to 4 | an edge node running the [Open Horizon](open-horizon.github.io/) agent. The workload can be configured as 5 | a managed service and policy in IBM Edge Application Manager. It queries 6 | psutil CPU data periodically and sends the CPU results over MQTT to 7 | Watson IoT Platform and plots the results in a chart. 8 | 9 | ![CPU Edge Node Telemetry Data](CPU-Edge-Node-Telemetry-Data.png) 10 | 11 | ### Prerequistes 12 | 13 | - Docker installed 14 | - IEAM Horizon agent installed 15 | 16 | ### 17 | 18 | Begin by editing the variables at the top of the Makefile as desired. If you plan to push it to a Docker registry, make sure you give your docker ID. You may also want to create unique names for your **service** and **policy** (necessary if you are running a multi-tentant IEAM instance with other users and you are all publishing this service). 19 | 20 | To play with this outside of Open Horizon: 21 | 22 | ```bash 23 | make build 24 | make run 25 | ... 26 | make stop 27 | ``` 28 | 29 | When you are ready to try it inside Open Horizon: 30 | 31 | ```bash 32 | docker login 33 | make build 34 | make push 35 | make publish-service 36 | make publish-policy 37 | ``` 38 | 39 | Once it is published, you can use: 40 | 41 | ```bash 42 | make agent-run 43 | watch hzn agreement list 44 | ... 45 | ``` 46 | -------------------------------------------------------------------------------- /messaging.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIElDCCA3ygAwIBAgIQAf2j627KdciIQ4tyS8+8kTANBgkqhkiG9w0BAQsFADBh 3 | MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 4 | d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD 5 | QTAeFw0xMzAzMDgxMjAwMDBaFw0yMzAzMDgxMjAwMDBaME0xCzAJBgNVBAYTAlVT 6 | MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxJzAlBgNVBAMTHkRpZ2lDZXJ0IFNIQTIg 7 | U2VjdXJlIFNlcnZlciBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB 8 | ANyuWJBNwcQwFZA1W248ghX1LFy949v/cUP6ZCWA1O4Yok3wZtAKc24RmDYXZK83 9 | nf36QYSvx6+M/hpzTc8zl5CilodTgyu5pnVILR1WN3vaMTIa16yrBvSqXUu3R0bd 10 | KpPDkC55gIDvEwRqFDu1m5K+wgdlTvza/P96rtxcflUxDOg5B6TXvi/TC2rSsd9f 11 | /ld0Uzs1gN2ujkSYs58O09rg1/RrKatEp0tYhG2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CmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg 45 | 06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF 46 | PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls 47 | YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk 48 | CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4= 49 | -----END CERTIFICATE----- 50 | 51 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # PSUtil service that sends the CPU output to Watson IoT Platform via MQTT 2 | 3 | DOCKERHUB_ID:=docker.io/walicki 4 | export SERVICE_NAME ?= "cpu-mqtt-example-instructor" 5 | export SERVICE_VERSION ?= 1.2 6 | export SERVICE_ORG_ID ?= $(HZN_ORG_ID) 7 | 8 | export CONTAINER_IMAGE_BASE ?= $(DOCKERHUB_ID)/$(SERVICE_NAME) 9 | export CONTAINER_IMAGE_VERSION ?= $(SERVICE_VERSION) 10 | 11 | # Leave blank for open DockerHub containers 12 | # CONTAINER_CREDS:=-r "registry.wherever.com:myid:mypw" 13 | # CONTAINER_CREDS:=-r "us.icr.io:iamapikey:$(IAMAPIKEY)" 14 | 15 | default: build run 16 | 17 | build: 18 | @docker build --platform linux/arm64 -t $(CONTAINER_IMAGE_BASE)_arm64:$(CONTAINER_IMAGE_VERSION) -f ./Dockerfile 19 | @docker build --platform linux/amd64 -t $(CONTAINER_IMAGE_BASE)_amd64:$(CONTAINER_IMAGE_VERSION) -f ./Dockerfile 20 | docker image prune --filter label=stage=builder --force 21 | 22 | dev: stop build 23 | docker run -it --name ${SERVICE_NAME} \ 24 | $(CONTAINER_IMAGE_BASE)_amd64:$(CONTAINER_IMAGE_VERSION) /bin/bash 25 | 26 | run: stop 27 | docker run -d \ 28 | --name ${SERVICE_NAME} \ 29 | --env-file secrets/env.list \ 30 | $(CONTAINER_IMAGE_BASE)_amd64:$(CONTAINER_IMAGE_VERSION) 31 | 32 | push: 33 | docker push $(CONTAINER_IMAGE_BASE)_arm64:$(SERVICE_VERSION) 34 | docker push $(CONTAINER_IMAGE_BASE)_amd64:$(SERVICE_VERSION) 35 | 36 | publish-service: 37 | @echo "==================" 38 | @echo "PUBLISHING SERVICE" 39 | @echo "==================" 40 | @ARCH=arm64 \ 41 | SERVICE_NAME="$(SERVICE_NAME)" \ 42 | SERVICE_VERSION="$(SERVICE_VERSION)"\ 43 | SERVICE_CONTAINER="$(CONTAINER_IMAGE_BASE)_arm64:$(CONTAINER_IMAGE_VERSION)" \ 44 | hzn exchange service publish -O $(CONTAINER_CREDS) -f service.json --dont-change-image-tag 45 | @ARCH=amd64 \ 46 | SERVICE_NAME="$(SERVICE_NAME)" \ 47 | SERVICE_VERSION="$(SERVICE_VERSION)"\ 48 | SERVICE_CONTAINER="$(CONTAINER_IMAGE_BASE)_amd64:$(CONTAINER_IMAGE_VERSION)" \ 49 | hzn exchange service publish -O $(CONTAINER_CREDS) -f service.json --dont-change-image-tag 50 | 51 | publish-policy: 52 | @ARCH=arm64 \ 53 | SERVICE_NAME="$(SERVICE_NAME)" \ 54 | SERVICE_VERSION="$(SERVICE_VERSION)" \ 55 | hzn exchange deployment addpolicy -f deployment-policy-mqtt.json ${HZN_ORG_ID}/policy-${SERVICE_NAME}_arm64_${SERVICE_VERSION} 56 | echo hzn exchange deployment addpolicy -f deployment-policy-mqtt.json ${HZN_ORG_ID}/policy-${SERVICE_NAME}_arm64_${SERVICE_VERSION} 57 | @ARCH=amd64 \ 58 | SERVICE_NAME="$(SERVICE_NAME)" \ 59 | SERVICE_VERSION="$(SERVICE_VERSION)" \ 60 | hzn exchange deployment addpolicy -f deployment-policy-mqtt.json ${HZN_ORG_ID}/policy-${SERVICE_NAME}_amd64_${SERVICE_VERSION} 61 | echo hzn exchange deployment addpolicy -f deployment-policy-mqtt.json ${HZN_ORG_ID}/policy-${SERVICE_NAME}_amd64_${SERVICE_VERSION} 62 | 63 | agent-run: 64 | @DOCKERHUB_ID="$(DOCKERHUB_ID)" \ 65 | hzn register --policy node-policy.json 66 | 67 | agent-stop: 68 | hzn unregister -f 69 | 70 | stop: 71 | @docker rm -f ${SERVICE_NAME} >/dev/null 2>&1 || : 72 | 73 | clean: 74 | -docker rmi $(CONTAINER_IMAGE_BASE)_arm64:$(CONTAINER_IMAGE_VERSION) 2> /dev/null || : 75 | -docker rmi $(CONTAINER_IMAGE_BASE)_amd64:$(CONTAINER_IMAGE_VERSION) 2> /dev/null || : 76 | @docker image prune --filter label=stage=builder --force 77 | 78 | .PHONY: build dev run push publish-service publish-policy stop clean 79 | -------------------------------------------------------------------------------- /psutil2mqtt.py: -------------------------------------------------------------------------------- 1 | import time 2 | import sys 3 | import psutil 4 | import json 5 | import os 6 | import ssl 7 | import paho.mqtt.client as mqtt 8 | 9 | # Get the value from an environment variable, or a default value if none was provided 10 | def get_from_env(v, d): 11 | if v in os.environ and '' != os.environ[v]: 12 | return os.environ[v] 13 | else: 14 | return d 15 | 16 | # Seconds to sleep between readings 17 | interval = 5 18 | global mqtt_disconnect 19 | 20 | # MQTT broker details - Set by the Horizon Deployment Policy 21 | orgID = get_from_env('MQTT_ORGID', '') 22 | deviceType = get_from_env('MQTT_DEVICETYPE', '') 23 | deviceID = get_from_env('MQTT_DEVICEID', '') 24 | deviceToken = get_from_env('MQTT_DEVICETOKEN','') 25 | 26 | host = orgID + '.messaging.internetofthings.ibmcloud.com' 27 | # clientID must follow Watson IoT Platform format or will fail to connect: 28 | # If you are connecting as a device use the following clientID 29 | # clientID = 'd:' + orgID + ':' + deviceType + ':' + deviceID 30 | clientID = 'd:' + orgID + ':' + deviceType + ':' + deviceID 31 | print(clientID) 32 | # Server certificate file 33 | #caFile = os.path.dirname(os.path.abspath(__file__)) + "/messaging.pem" 34 | caFile = "./messaging.pem" 35 | # Topics must follow platform format (see docs for details) 36 | # Publish and subscribe as a device 37 | publishTopic = 'iot-2/evt/status/fmt/json' 38 | global connected 39 | connected = False 40 | 41 | # MQTT callback functions 42 | def on_connect(mqttclient, userdata, flags, rc): 43 | global connected 44 | print("client connected:", rc) 45 | connected = True 46 | 47 | 48 | # Create the MQTT client, set the authentication details and register callbacks 49 | mqttclient = mqtt.Client(clientID, protocol=mqtt.MQTTv311) 50 | mqttclient.username_pw_set("use-token-auth", deviceToken) 51 | mqttclient.tls_set(ca_certs=caFile, certfile=None, keyfile=None, cert_reqs=ssl.CERT_REQUIRED, tls_version=ssl.PROTOCOL_TLSv1_2) 52 | mqttclient.on_connect = on_connect 53 | 54 | # Connect the client and start the handler loop 55 | mqttclient.connect(host, port=8883, keepalive=600) 56 | mqttclient.loop_start() 57 | 58 | # Take initial CPU readings 59 | psutil.cpu_percent(percpu=False) 60 | before_ts = time.time() 61 | ioBefore = psutil.net_io_counters() 62 | diskBefore = psutil.disk_io_counters() 63 | psutil.disk_io_counters(perdisk=False, nowrap=True) 64 | 65 | while True: 66 | try: 67 | time.sleep(interval) 68 | after_ts = time.time() 69 | ioAfter = psutil.net_io_counters() 70 | diskAfter = psutil.disk_io_counters() 71 | # Calculate the time taken between IO checks 72 | duration = after_ts - before_ts 73 | 74 | data = { 75 | "node": get_from_env('HZN_NODE_ID',''), 76 | "cpu": psutil.cpu_percent(percpu=False), 77 | "mem": psutil.virtual_memory().percent, 78 | "network": { 79 | "up": round((ioAfter.bytes_sent - ioBefore.bytes_sent) / (duration * 1024), 2), 80 | "down": round((ioAfter.bytes_recv - ioBefore.bytes_recv) / (duration * 1024), 2), 81 | }, 82 | "disk": { 83 | "read": round((diskAfter.read_bytes - diskBefore.read_bytes) / (duration * 1024), 2), 84 | "write": round((diskAfter.write_bytes - diskBefore.write_bytes) / (duration * 1024), 2), 85 | }, 86 | } 87 | if True: 88 | print("CPU Data = " + json.dumps(data)) 89 | 90 | if connected: 91 | mqttclient.publish(publishTopic, payload=json.dumps(data), qos=1, retain=False) 92 | time.sleep(.25) # rate limit the amount of data sent to the MQTT broker 93 | 94 | except KeyboardInterrupt: 95 | # stop the handler loop 96 | print("MQTT Connection closed") 97 | mqttclient.loop_stop() 98 | sys.exit() 99 | 100 | # Update timestamp and data ready for next loop 101 | before_ts = after_ts 102 | ioBefore = ioAfter 103 | diskBefore = diskAfter 104 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------