From c373f7d4682eda9b45ad6abe568396586d0cb11d Mon Sep 17 00:00:00 2001 From: Rick Kauffman Date: Sat, 19 Feb 2022 11:55:25 -0700 Subject: [PATCH 1/7] new stackstorm pack for morpheus --- stackstorm-morpheus/CHANGES.md | 3 + stackstorm-morpheus/LICENSE | 201 ++++++++++++++++++ stackstorm-morpheus/README.md | 76 +++++++ stackstorm-morpheus/actions/get-mongo-logs.py | 58 +++++ .../actions/get-mongo-logs.yaml | 7 + stackstorm-morpheus/actions/get_logs.py | 55 +++++ stackstorm-morpheus/actions/get_logs.yaml | 7 + stackstorm-morpheus/actions/lib/__init__.py | 1 + stackstorm-morpheus/actions/lib/actions.py | 60 ++++++ .../actions/load-morpheus-logs.py | 60 ++++++ .../actions/load-morpheus-logs.yaml | 11 + .../actions/mongo-logs-2-splunk.yaml | 6 + .../actions/morpheus-logs-2-mongo.yaml | 6 + stackstorm-morpheus/actions/process_logs.py | 37 ++++ stackstorm-morpheus/actions/process_logs.yaml | 11 + .../workflows/mongo-logs-2-splunk.yaml | 23 ++ .../workflows/morpheus-logs-2-mongo.yaml | 15 ++ stackstorm-morpheus/config.schema.yaml | 15 ++ stackstorm-morpheus/icon.png | Bin 0 -> 3834 bytes stackstorm-morpheus/lib/__init__.py | 1 + stackstorm-morpheus/lib/actions.py | 60 ++++++ stackstorm-morpheus/morpheus.yaml.example | 6 + stackstorm-morpheus/pack.yaml | 12 ++ stackstorm-morpheus/requirements.txt | 3 + .../rules/mongo-logs-2-splunk.yaml | 13 ++ .../rules/morpheus-logs-2-mongo.yaml | 13 ++ stackstorm-morpheus/sensors/readme.md | 1 + 27 files changed, 761 insertions(+) create mode 100644 stackstorm-morpheus/CHANGES.md create mode 100644 stackstorm-morpheus/LICENSE create mode 100644 stackstorm-morpheus/README.md create mode 100644 stackstorm-morpheus/actions/get-mongo-logs.py create mode 100644 stackstorm-morpheus/actions/get-mongo-logs.yaml create mode 100644 stackstorm-morpheus/actions/get_logs.py create mode 100644 stackstorm-morpheus/actions/get_logs.yaml create mode 100644 stackstorm-morpheus/actions/lib/__init__.py create mode 100644 stackstorm-morpheus/actions/lib/actions.py create mode 100644 stackstorm-morpheus/actions/load-morpheus-logs.py create mode 100644 stackstorm-morpheus/actions/load-morpheus-logs.yaml create mode 100644 stackstorm-morpheus/actions/mongo-logs-2-splunk.yaml create mode 100644 stackstorm-morpheus/actions/morpheus-logs-2-mongo.yaml create mode 100644 stackstorm-morpheus/actions/process_logs.py create mode 100644 stackstorm-morpheus/actions/process_logs.yaml create mode 100644 stackstorm-morpheus/actions/workflows/mongo-logs-2-splunk.yaml create mode 100644 stackstorm-morpheus/actions/workflows/morpheus-logs-2-mongo.yaml create mode 100644 stackstorm-morpheus/config.schema.yaml create mode 100644 stackstorm-morpheus/icon.png create mode 100644 stackstorm-morpheus/lib/__init__.py create mode 100644 stackstorm-morpheus/lib/actions.py create mode 100644 stackstorm-morpheus/morpheus.yaml.example create mode 100644 stackstorm-morpheus/pack.yaml create mode 100644 stackstorm-morpheus/requirements.txt create mode 100644 stackstorm-morpheus/rules/mongo-logs-2-splunk.yaml create mode 100644 stackstorm-morpheus/rules/morpheus-logs-2-mongo.yaml create mode 100644 stackstorm-morpheus/sensors/readme.md diff --git a/stackstorm-morpheus/CHANGES.md b/stackstorm-morpheus/CHANGES.md new file mode 100644 index 00000000..5f5874b5 --- /dev/null +++ b/stackstorm-morpheus/CHANGES.md @@ -0,0 +1,3 @@ +Current status : Alpha +Version : 0.1.0 +-initial release diff --git a/stackstorm-morpheus/LICENSE b/stackstorm-morpheus/LICENSE new file mode 100644 index 00000000..261eeb9e --- /dev/null +++ b/stackstorm-morpheus/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/stackstorm-morpheus/README.md b/stackstorm-morpheus/README.md new file mode 100644 index 00000000..85f443aa --- /dev/null +++ b/stackstorm-morpheus/README.md @@ -0,0 +1,76 @@ +# Morpheus Integration Pack +This pack allows you to integrate with Morpheus + +## Configuration +Copy the example configuration in [morpheus.yaml.example](./morpheus.yaml.example) to +`/opt/stackstorm/configs/morpheus.yaml` and edit as required. + +It must contain: + +``` +ipaddress - Your Morpheus Appliance IP address +username - Morpheus User name +password - Morpheus Password +dbuser - Mongo database username +dbpass - Mongo database password +``` + +You can also use dynamic values from the datastore. See the +[docs](https://docs.stackstorm.com/reference/pack_configs.html) for more info. + +Example configuration: + +```yaml +--- + ipaddress: "10.10.10.10" + username: "Administrator" + password: "password" + dbuser: "appUser" + dbpass: "passwordForAppUser" +``` +You can also run `st2 pack config morpheus` and answer the prompts + +**Note** : When modifying the configuration in `/opt/stackstorm/configs/` please + remember to tell StackStorm to load these new values by running + `st2ctl reload --register-configs` + + +## Actions + +Actions are defined in two groups: + +### Individual actions: GET, POST, PUT with under bar will precede each individual action +* ``get_volumes`` +* ``get_logs`` +* ``get_networks`` +* ``get_alerts`` + +### Orquestra Workflows: will not + +This application uses the mongo db installed by StackStorm. Since the DB is secured +you will need to log into the StackStorm mongo DB as a StackStorm admin and create a separate DB + +# To get this pack to work with A SINGLE HOST DEPLOYMENT StackStorm mongo DB +You can ignore this section when using StackStorm in docker containers. There is +no username and password associated with the database running in the mongo container. +Use at your own discretion. + +``` +docker pull stackstorm/stackstorm +``` + +log in with admin first +-------------------------------------------------------------------------------------- +mongo -u admin -p UkIbDILcNbMhkh3KtN6xfr9h admin (passwd in /etc/st2/st2.config) + +# Then create a new user +db.createUser({user: "appUser",pwd: "passwordForAppUser",roles: [ { role: "readWrite", db: "app_db" } ]}) + +# Then if necessary you can check the mongo database records by +mongo -u appUser -p passwordForAppUser admin + +# Servicenow Tables + +![Logs - Event information](/img/morpheus-logs-table.png) +Event fields in service now: +u_category, u_id, u_severity, u_time, u_summary diff --git a/stackstorm-morpheus/actions/get-mongo-logs.py b/stackstorm-morpheus/actions/get-mongo-logs.py new file mode 100644 index 00000000..1cd5ec0e --- /dev/null +++ b/stackstorm-morpheus/actions/get-mongo-logs.py @@ -0,0 +1,58 @@ + + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0. + +# Unless required by applicable law. or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# __author__ = "@netwookie" +# __credits__ = ["Rick Kauffman"] +# __license__ = "Apache2.0" +# __maintainer__ = "Rick Kauffman" +# __email__ = "rick#rickkauffman.com" + +from lib.actions import MongoBaseAction +import json + +__all__ = [ + 'GetDb' +] + + +class GetDb(MongoBaseAction): + def run(self): + + mydb = self.dbclient["app_db"] + known = mydb["morpheuslogs"] + + list_to_process = [] + log = {} + + myquery = {"u_process": 'no'} + records = list(known.find(myquery)) + + for r in records: + log['u_typeCode'] = r['u_typeCode'] + log['u_ts'] = r['u_ts'] + log['u_level'] = r['u_level'] + log['u_sourceType'] = r['u_sourceType'] + log['u_message'] = r['u_message'] + log['u_hostname'] = r['u_hostname'] + log['u_title'] = r['u_title'] + log['u_logSignature'] = r['u_logSignature'] + log['u_objectId'] = r['u_objectId'] + log['u_seq'] = r['u_seq'] + log['u_id'] = r['u_id'] + log['u_signatureVerified'] = r['u_signatureVerified'] + log = json.dumps(log) + list_to_process.append(log) + log = {} + + return (list_to_process) diff --git a/stackstorm-morpheus/actions/get-mongo-logs.yaml b/stackstorm-morpheus/actions/get-mongo-logs.yaml new file mode 100644 index 00000000..f8ac1986 --- /dev/null +++ b/stackstorm-morpheus/actions/get-mongo-logs.yaml @@ -0,0 +1,7 @@ +--- +name: get-mongo-logs +pack: morpheus +description: Get Morpheus logs from mongo db +runner_type: python-script +entry_point: get-mongo-logs.py +enabled: true diff --git a/stackstorm-morpheus/actions/get_logs.py b/stackstorm-morpheus/actions/get_logs.py new file mode 100644 index 00000000..7b7ef809 --- /dev/null +++ b/stackstorm-morpheus/actions/get_logs.py @@ -0,0 +1,55 @@ + + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# __author__ = "@netwookie" +# __credits__ = ["Rick Kauffman"] +# __license__ = "Apache2.0" +# __maintainer__ = "Rick Kauffman" +# __email__ = "rick@rickkauffman.com" + +import urllib3 +from lib.actions import MorpheusBaseAction +from pypheus.logs import Logs +urllib3.disable_warnings() + +__all__ = [ + 'LogData' +] + + +class LogData(MorpheusBaseAction): + def run(self): + log_list = [] + logs = Logs(self.client[0], self.client[1], self.client[2]) + log_data = logs.get_all_logs() + + for i in log_data['data']: + info = [ + i['typeCode'], + i['ts'], + i['level'], + i['sourceType'], + i['message'], + i['hostname'], + i['title'], + i['logSignature'], + i['objectId'], + i['seq'], + i['_id'], + i['signatureVerified'] + ] + + log_list.append(info) + info = [] + return log_list diff --git a/stackstorm-morpheus/actions/get_logs.yaml b/stackstorm-morpheus/actions/get_logs.yaml new file mode 100644 index 00000000..c4853367 --- /dev/null +++ b/stackstorm-morpheus/actions/get_logs.yaml @@ -0,0 +1,7 @@ +--- +name: get_logs +pack: morpheus +description: Get an array of all logs from Morpheus +runner_type: python-script +entry_point: get_logs.py +enabled: true diff --git a/stackstorm-morpheus/actions/lib/__init__.py b/stackstorm-morpheus/actions/lib/__init__.py new file mode 100644 index 00000000..792d6005 --- /dev/null +++ b/stackstorm-morpheus/actions/lib/__init__.py @@ -0,0 +1 @@ +# diff --git a/stackstorm-morpheus/actions/lib/actions.py b/stackstorm-morpheus/actions/lib/actions.py new file mode 100644 index 00000000..71b528d9 --- /dev/null +++ b/stackstorm-morpheus/actions/lib/actions.py @@ -0,0 +1,60 @@ + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# __author__ = "@netwookie" +# __credits__ = ["Rick Kauffman"] +# __license__ = "Apache2.0" +# __maintainer__ = "Rick Kauffman." +# __email__ = "rick@riickkauffman.com" + +from pymongo import MongoClient +from st2common.runners.base_action import Action + +__all__ = [ + 'MorpheusBaseAction' +] + + +class MorpheusBaseAction(Action): + def __init__(self, config): + super(MorpheusBaseAction, self).__init__(config=config) + self.client = self._get_client() + + def _get_client(self): + host = self.config['host'] + username = self.config['username'] + password = self.config['password'] + + client = [host, username, password] + + return client + + +class MongoBaseAction(Action): + def __init__(self, config): + super(MongoBaseAction, self).__init__(config=config) + self.dbclient = self._get_db_client() + + def _get_db_client(self): + # Uncomment dbuser & dbpass if using password protected mongo database + # dbuser = self.config['dbuser'] + # dbpass = self.config['dbpass'] + + # If running stackstorm in a singlehost deployment use this command + # dbclient = + # MongoClient('mongodb://%s:%s@localhost:27017/' % (dbuser,dbpass)) + + # If youing stackstorm in multiple docker containers use this command + dbclient = MongoClient('mongodb://mongo:27017/') + + return dbclient diff --git a/stackstorm-morpheus/actions/load-morpheus-logs.py b/stackstorm-morpheus/actions/load-morpheus-logs.py new file mode 100644 index 00000000..779880f4 --- /dev/null +++ b/stackstorm-morpheus/actions/load-morpheus-logs.py @@ -0,0 +1,60 @@ + + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0. + +# Unless required by applicable law. or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# __author__ = "@netwookie" +# __credits__ = ["Rick Kauffman"] +# __license__ = "Apache2.0" +# __maintainer__ = "Rick Kauffman" +# __email__ = "rick#rickkauffman.com" + +from lib.actions import MongoBaseAction + +__all__ = [ + 'LoadDb' +] + + +class LoadDb(MongoBaseAction): + def run(self, logs): + + mydb = self.dbclient["app_db"] + known = mydb["morpheuslogs"] + + new_log = {} + + for log in logs: + myquery = {"u_id": logs[10]} + records = known.find(myquery).count() + if records == 0: + new_log['u_typeCode'] = log[0] + new_log['u_ts'] = log[1] + new_log['u_level'] = log[2] + new_log['u_sourceType'] = log[3] + new_log['u_message'] = log[4] + new_log['u_hostname'] = log[5] + new_log['u_title'] = log[6] + new_log['u_logSignature'] = log[7] + new_log['u_objectId'] = log[8] + new_log['u_seq'] = log[9] + new_log['u_id'] = log[10] + new_log['u_signatureVerified'] = log[11] + new_log['u_process'] = 'no' + write_record = known.insert_one(new_log) + print(write_record) + new_log = {} + + else: + records = 'Fail to write mongo record, possible duplicate' + # write_record = process.insert_one(alarm) + return (records) diff --git a/stackstorm-morpheus/actions/load-morpheus-logs.yaml b/stackstorm-morpheus/actions/load-morpheus-logs.yaml new file mode 100644 index 00000000..3e3557aa --- /dev/null +++ b/stackstorm-morpheus/actions/load-morpheus-logs.yaml @@ -0,0 +1,11 @@ +--- +name: load-morpheus-logs +pack: morpheus +description: load Morpheus logs into the mongo db +runner_type: python-script +entry_point: load-morpheus-logs.py +enabled: true +parameters: + logs: + required: true + type: array diff --git a/stackstorm-morpheus/actions/mongo-logs-2-splunk.yaml b/stackstorm-morpheus/actions/mongo-logs-2-splunk.yaml new file mode 100644 index 00000000..dcd3be52 --- /dev/null +++ b/stackstorm-morpheus/actions/mongo-logs-2-splunk.yaml @@ -0,0 +1,6 @@ +--- +name: mongo-logs-2-splunk +description: A workflow for sending morpheus logs from mongo to splunk. +runner_type: orquesta +entry_point: workflows/mongo-logs-2-splunk.yaml +enabled: true diff --git a/stackstorm-morpheus/actions/morpheus-logs-2-mongo.yaml b/stackstorm-morpheus/actions/morpheus-logs-2-mongo.yaml new file mode 100644 index 00000000..a9cfc778 --- /dev/null +++ b/stackstorm-morpheus/actions/morpheus-logs-2-mongo.yaml @@ -0,0 +1,6 @@ +--- +name: morpheus-logs-2-mongo +description: A workflow for getting morpheus logs into a mongo database. +runner_type: orquesta +entry_point: workflows/morpheus-logs-2-mongo.yaml +enabled: true diff --git a/stackstorm-morpheus/actions/process_logs.py b/stackstorm-morpheus/actions/process_logs.py new file mode 100644 index 00000000..3ddf1167 --- /dev/null +++ b/stackstorm-morpheus/actions/process_logs.py @@ -0,0 +1,37 @@ + + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0. + +# Unless required by applicable law. or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# __author__ = "@netwookie" +# __credits__ = ["Rick Kauffman"] +# __license__ = "Apache2.0" +# __maintainer__ = "Rick Kauffman" +# __email__ = "rick@rickkauffman.com" + +from lib.actions import MongoBaseAction + +__all__ = [ + 'LoadDb' +] + + +class LoadDb(MongoBaseAction): + def run(self, logs): + + mydb = self.dbclient["app_db"] + col = mydb["morpheus-logs"] + + for log in logs: + col.updateOne({"_id": log['_id']}, {"$set": {"u_process": "yes"}}) + + return () diff --git a/stackstorm-morpheus/actions/process_logs.yaml b/stackstorm-morpheus/actions/process_logs.yaml new file mode 100644 index 00000000..f4589c35 --- /dev/null +++ b/stackstorm-morpheus/actions/process_logs.yaml @@ -0,0 +1,11 @@ +--- +name: process_logs +pack: morpheus +description: Set the process flag in the mongo database for logs to yes +runner_type: python-script +entry_point: process_logs.py +enabled: true +parameters: + logs: + required: true + type: array diff --git a/stackstorm-morpheus/actions/workflows/mongo-logs-2-splunk.yaml b/stackstorm-morpheus/actions/workflows/mongo-logs-2-splunk.yaml new file mode 100644 index 00000000..5deda8e8 --- /dev/null +++ b/stackstorm-morpheus/actions/workflows/mongo-logs-2-splunk.yaml @@ -0,0 +1,23 @@ +version: 1.0 + +description: A workflow to copy Morpheus logs from mongo and into splunk.. + +tasks: + gettoken: + action: splunk.get_hec_token instance="prod" + next: + - when: <% succeeded() %> + publish: + - token: <% result().result %> + do: getlogs + getlogs: + action: morpheus.get-mongo-logs + next: + - when: <% succeeded() %> + publish: + - logs: <% result().result %> + do: sendsplunk + + sendsplunk: + with: <% ctx().logs %> + action: splunk.send_log instance="prod" index="main" token=<% ctx().token %> event='<% item() %>' diff --git a/stackstorm-morpheus/actions/workflows/morpheus-logs-2-mongo.yaml b/stackstorm-morpheus/actions/workflows/morpheus-logs-2-mongo.yaml new file mode 100644 index 00000000..4d1e223b --- /dev/null +++ b/stackstorm-morpheus/actions/workflows/morpheus-logs-2-mongo.yaml @@ -0,0 +1,15 @@ +version: 1.0 + +description: A workflow to copy hpe nimble alarms into a mongo database. + +tasks: + getalarms: + action: morpheus.get_logs + next: + - when: <% succeeded() %> + publish: + - logs: <% result().result %> + do: sendmongo + + sendmongo: + action: morpheus.load-morpheus-logs logs=<% ctx().logs %> diff --git a/stackstorm-morpheus/config.schema.yaml b/stackstorm-morpheus/config.schema.yaml new file mode 100644 index 00000000..6ee60c70 --- /dev/null +++ b/stackstorm-morpheus/config.schema.yaml @@ -0,0 +1,15 @@ +--- +host: + description: "IP address of the Morpheus (e.g.: 'fqdn.to.device' or '10.10.10.10')" + type: "string" + secret: false + required: true +username: + description: "Username for Morpheus" + type: "string" + required: true +password: + description: "Password for Morpheus" + type: "string" + secret: true + required: true diff --git a/stackstorm-morpheus/icon.png b/stackstorm-morpheus/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..fd390ef451312733640aed8acb6f735bdf19cfc1 GIT binary patch literal 3834 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 literal 0 HcmV?d00001 diff --git a/stackstorm-morpheus/lib/__init__.py b/stackstorm-morpheus/lib/__init__.py new file mode 100644 index 00000000..792d6005 --- /dev/null +++ b/stackstorm-morpheus/lib/__init__.py @@ -0,0 +1 @@ +# diff --git a/stackstorm-morpheus/lib/actions.py b/stackstorm-morpheus/lib/actions.py new file mode 100644 index 00000000..71b528d9 --- /dev/null +++ b/stackstorm-morpheus/lib/actions.py @@ -0,0 +1,60 @@ + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# __author__ = "@netwookie" +# __credits__ = ["Rick Kauffman"] +# __license__ = "Apache2.0" +# __maintainer__ = "Rick Kauffman." +# __email__ = "rick@riickkauffman.com" + +from pymongo import MongoClient +from st2common.runners.base_action import Action + +__all__ = [ + 'MorpheusBaseAction' +] + + +class MorpheusBaseAction(Action): + def __init__(self, config): + super(MorpheusBaseAction, self).__init__(config=config) + self.client = self._get_client() + + def _get_client(self): + host = self.config['host'] + username = self.config['username'] + password = self.config['password'] + + client = [host, username, password] + + return client + + +class MongoBaseAction(Action): + def __init__(self, config): + super(MongoBaseAction, self).__init__(config=config) + self.dbclient = self._get_db_client() + + def _get_db_client(self): + # Uncomment dbuser & dbpass if using password protected mongo database + # dbuser = self.config['dbuser'] + # dbpass = self.config['dbpass'] + + # If running stackstorm in a singlehost deployment use this command + # dbclient = + # MongoClient('mongodb://%s:%s@localhost:27017/' % (dbuser,dbpass)) + + # If youing stackstorm in multiple docker containers use this command + dbclient = MongoClient('mongodb://mongo:27017/') + + return dbclient diff --git a/stackstorm-morpheus/morpheus.yaml.example b/stackstorm-morpheus/morpheus.yaml.example new file mode 100644 index 00000000..003a2e34 --- /dev/null +++ b/stackstorm-morpheus/morpheus.yaml.example @@ -0,0 +1,6 @@ +--- +host: "172.18.1.66" +username: "Administrator" +password: "Ch@ng3Me!" +dbuser: "appUser" +dbpass: 'passwordForAppUser' diff --git a/stackstorm-morpheus/pack.yaml b/stackstorm-morpheus/pack.yaml new file mode 100644 index 00000000..1f0df683 --- /dev/null +++ b/stackstorm-morpheus/pack.yaml @@ -0,0 +1,12 @@ +--- +ref: morpheus +name: morpheus +description: Morpheus Integration Pack +keywords: + - Morpheus + - Automation +version: 0.1.0 +python_versions: + - "3" +author: Rick Kauffman +email: rick@rickkauffman.com diff --git a/stackstorm-morpheus/requirements.txt b/stackstorm-morpheus/requirements.txt new file mode 100644 index 00000000..8af23078 --- /dev/null +++ b/stackstorm-morpheus/requirements.txt @@ -0,0 +1,3 @@ +urllib3 +requests +pypheus diff --git a/stackstorm-morpheus/rules/mongo-logs-2-splunk.yaml b/stackstorm-morpheus/rules/mongo-logs-2-splunk.yaml new file mode 100644 index 00000000..ea0de38f --- /dev/null +++ b/stackstorm-morpheus/rules/mongo-logs-2-splunk.yaml @@ -0,0 +1,13 @@ +--- +name: "mongo-logs-2-splunk" +description: "Get mongo logs and send to splunk." +enabled: false + +trigger: + type: "core.st2.IntervalTimer" + parameters: + delta: 5 + unit: minutes + +action: + ref: "morpheus.mongo-logs-2-splunk" diff --git a/stackstorm-morpheus/rules/morpheus-logs-2-mongo.yaml b/stackstorm-morpheus/rules/morpheus-logs-2-mongo.yaml new file mode 100644 index 00000000..4567df36 --- /dev/null +++ b/stackstorm-morpheus/rules/morpheus-logs-2-mongo.yaml @@ -0,0 +1,13 @@ +--- +name: "morpheus-logs-2-mongo" +description: "Get morpheus logs and send to mongo." +enabled: false + +trigger: + type: "core.st2.IntervalTimer" + parameters: + delta: 5 + unit: minutes + +action: + ref: "morpheus.morpheus-logs-2-mongo" diff --git a/stackstorm-morpheus/sensors/readme.md b/stackstorm-morpheus/sensors/readme.md new file mode 100644 index 00000000..792d6005 --- /dev/null +++ b/stackstorm-morpheus/sensors/readme.md @@ -0,0 +1 @@ +# From 265cc43d3de4b805569af54c546ec294e9e57799 Mon Sep 17 00:00:00 2001 From: Rick Kauffman Date: Sat, 19 Feb 2022 11:57:42 -0700 Subject: [PATCH 2/7] cleaned up README.md file --- stackstorm-morpheus/README.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/stackstorm-morpheus/README.md b/stackstorm-morpheus/README.md index 85f443aa..7d4addf6 100644 --- a/stackstorm-morpheus/README.md +++ b/stackstorm-morpheus/README.md @@ -54,7 +54,7 @@ you will need to log into the StackStorm mongo DB as a StackStorm admin and crea You can ignore this section when using StackStorm in docker containers. There is no username and password associated with the database running in the mongo container. Use at your own discretion. - + ``` docker pull stackstorm/stackstorm ``` @@ -68,9 +68,3 @@ db.createUser({user: "appUser",pwd: "passwordForAppUser",roles: [ { role: "readW # Then if necessary you can check the mongo database records by mongo -u appUser -p passwordForAppUser admin - -# Servicenow Tables - -![Logs - Event information](/img/morpheus-logs-table.png) -Event fields in service now: -u_category, u_id, u_severity, u_time, u_summary From 9bc686441f0c1f65c3121ef024335003a6adb9bd Mon Sep 17 00:00:00 2001 From: Rick Kauffman Date: Sat, 19 Feb 2022 12:06:11 -0700 Subject: [PATCH 3/7] fixed some flake8 issues --- stackstorm-morpheus/actions/get_logs.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/stackstorm-morpheus/actions/get_logs.py b/stackstorm-morpheus/actions/get_logs.py index 7b7ef809..236adefa 100644 --- a/stackstorm-morpheus/actions/get_logs.py +++ b/stackstorm-morpheus/actions/get_logs.py @@ -36,19 +36,18 @@ def run(self): for i in log_data['data']: info = [ - i['typeCode'], - i['ts'], - i['level'], - i['sourceType'], - i['message'], - i['hostname'], - i['title'], - i['logSignature'], - i['objectId'], - i['seq'], - i['_id'], - i['signatureVerified'] - ] + i['typeCode'], + i['ts'], + i['level'], + i['sourceType'], + i['message'], + i['hostname'], + i['title'], + i['logSignature'], + i['objectId'], + i['seq'], + i['_id'], + i['signatureVerified']] log_list.append(info) info = [] From 803f881ed75d005b816bd722cf847a18cc6ce18f Mon Sep 17 00:00:00 2001 From: Rick Kauffman Date: Wed, 25 May 2022 11:05:21 -0700 Subject: [PATCH 4/7] made chages to readme --- stackstorm-morpheus/README.md | 30 +++++------ stackstorm-morpheus/actions/lib/__init__.py | 2 +- stackstorm-morpheus/lib/__init__.py | 1 - stackstorm-morpheus/lib/actions.py | 60 --------------------- 4 files changed, 14 insertions(+), 79 deletions(-) delete mode 100644 stackstorm-morpheus/lib/__init__.py delete mode 100644 stackstorm-morpheus/lib/actions.py diff --git a/stackstorm-morpheus/README.md b/stackstorm-morpheus/README.md index 7d4addf6..b3c136e1 100644 --- a/stackstorm-morpheus/README.md +++ b/stackstorm-morpheus/README.md @@ -37,34 +37,30 @@ You can also run `st2 pack config morpheus` and answer the prompts ## Actions -Actions are defined in two groups: +###Action naming conventions: -### Individual actions: GET, POST, PUT with under bar will precede each individual action +Individual actions: Action names will have an underscore after the HTTP method * ``get_volumes`` * ``get_logs`` * ``get_networks`` * ``get_alerts`` -### Orquestra Workflows: will not +Orquestra Workflows: will have a dash. -This application uses the mongo db installed by StackStorm. Since the DB is secured -you will need to log into the StackStorm mongo DB as a StackStorm admin and create a separate DB +## Mongo considerations -# To get this pack to work with A SINGLE HOST DEPLOYMENT StackStorm mongo DB -You can ignore this section when using StackStorm in docker containers. There is -no username and password associated with the database running in the mongo container. -Use at your own discretion. +If your mongo instance does not have auth enabled, then you don't need to +provide a dbuser and dbpass -``` -docker pull stackstorm/stackstorm -``` +If the default mongoDB is used and it has authentication enabled, you will +need to create a new user and a database. + +This can be done by logging in as admin using the following example. -log in with admin first --------------------------------------------------------------------------------------- -mongo -u admin -p UkIbDILcNbMhkh3KtN6xfr9h admin (passwd in /etc/st2/st2.config) +mongo -u admin -p admin -# Then create a new user +### Then create a new user db.createUser({user: "appUser",pwd: "passwordForAppUser",roles: [ { role: "readWrite", db: "app_db" } ]}) -# Then if necessary you can check the mongo database records by +### Then if necessary you can check the mongo database records by mongo -u appUser -p passwordForAppUser admin diff --git a/stackstorm-morpheus/actions/lib/__init__.py b/stackstorm-morpheus/actions/lib/__init__.py index 792d6005..8b137891 100644 --- a/stackstorm-morpheus/actions/lib/__init__.py +++ b/stackstorm-morpheus/actions/lib/__init__.py @@ -1 +1 @@ -# + diff --git a/stackstorm-morpheus/lib/__init__.py b/stackstorm-morpheus/lib/__init__.py deleted file mode 100644 index 792d6005..00000000 --- a/stackstorm-morpheus/lib/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# diff --git a/stackstorm-morpheus/lib/actions.py b/stackstorm-morpheus/lib/actions.py deleted file mode 100644 index 71b528d9..00000000 --- a/stackstorm-morpheus/lib/actions.py +++ /dev/null @@ -1,60 +0,0 @@ - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# __author__ = "@netwookie" -# __credits__ = ["Rick Kauffman"] -# __license__ = "Apache2.0" -# __maintainer__ = "Rick Kauffman." -# __email__ = "rick@riickkauffman.com" - -from pymongo import MongoClient -from st2common.runners.base_action import Action - -__all__ = [ - 'MorpheusBaseAction' -] - - -class MorpheusBaseAction(Action): - def __init__(self, config): - super(MorpheusBaseAction, self).__init__(config=config) - self.client = self._get_client() - - def _get_client(self): - host = self.config['host'] - username = self.config['username'] - password = self.config['password'] - - client = [host, username, password] - - return client - - -class MongoBaseAction(Action): - def __init__(self, config): - super(MongoBaseAction, self).__init__(config=config) - self.dbclient = self._get_db_client() - - def _get_db_client(self): - # Uncomment dbuser & dbpass if using password protected mongo database - # dbuser = self.config['dbuser'] - # dbpass = self.config['dbpass'] - - # If running stackstorm in a singlehost deployment use this command - # dbclient = - # MongoClient('mongodb://%s:%s@localhost:27017/' % (dbuser,dbpass)) - - # If youing stackstorm in multiple docker containers use this command - dbclient = MongoClient('mongodb://mongo:27017/') - - return dbclient From 549ff9630edcc1ffc2a993a7b866615c3ec5ef04 Mon Sep 17 00:00:00 2001 From: Rick Kauffman Date: Wed, 25 May 2022 11:46:56 -0700 Subject: [PATCH 5/7] made changed schema to add dbuser-dbpass as not required --- stackstorm-morpheus/config.schema.yaml | 10 ++++++++++ stackstorm-morpheus/morpheus.yaml.example | 2 -- stackstorm-morpheus/sensors/readme.md | 1 - 3 files changed, 10 insertions(+), 3 deletions(-) delete mode 100644 stackstorm-morpheus/sensors/readme.md diff --git a/stackstorm-morpheus/config.schema.yaml b/stackstorm-morpheus/config.schema.yaml index 6ee60c70..0632bbb9 100644 --- a/stackstorm-morpheus/config.schema.yaml +++ b/stackstorm-morpheus/config.schema.yaml @@ -13,3 +13,13 @@ password: type: "string" secret: true required: true +dbuser: + description: "Username for user database" + type: "string" + secret: false + required: false +dbpass: + description: "Password for user database" + type: "string" + secret: true + required: false diff --git a/stackstorm-morpheus/morpheus.yaml.example b/stackstorm-morpheus/morpheus.yaml.example index 003a2e34..dfc7b2aa 100644 --- a/stackstorm-morpheus/morpheus.yaml.example +++ b/stackstorm-morpheus/morpheus.yaml.example @@ -2,5 +2,3 @@ host: "172.18.1.66" username: "Administrator" password: "Ch@ng3Me!" -dbuser: "appUser" -dbpass: 'passwordForAppUser' diff --git a/stackstorm-morpheus/sensors/readme.md b/stackstorm-morpheus/sensors/readme.md deleted file mode 100644 index 792d6005..00000000 --- a/stackstorm-morpheus/sensors/readme.md +++ /dev/null @@ -1 +0,0 @@ -# From dc268e3c5cd90ca423d8b9b379a6fc7e2e2a590b Mon Sep 17 00:00:00 2001 From: Rick Kauffman Date: Wed, 25 May 2022 12:20:42 -0700 Subject: [PATCH 6/7] fixed lib/actions.py to manage db user --- stackstorm-morpheus/actions/lib/actions.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/stackstorm-morpheus/actions/lib/actions.py b/stackstorm-morpheus/actions/lib/actions.py index 71b528d9..413da624 100644 --- a/stackstorm-morpheus/actions/lib/actions.py +++ b/stackstorm-morpheus/actions/lib/actions.py @@ -46,15 +46,11 @@ def __init__(self, config): self.dbclient = self._get_db_client() def _get_db_client(self): - # Uncomment dbuser & dbpass if using password protected mongo database - # dbuser = self.config['dbuser'] - # dbpass = self.config['dbpass'] - - # If running stackstorm in a singlehost deployment use this command - # dbclient = - # MongoClient('mongodb://%s:%s@localhost:27017/' % (dbuser,dbpass)) - - # If youing stackstorm in multiple docker containers use this command - dbclient = MongoClient('mongodb://mongo:27017/') - + if self.config['dbuser']: + dbuser = self.config['dbuser'] + dbpass = self.config['dbpass'] + dbclient = MongoClient('mongodb://%s:%s@localhost:27017/' % + (dbuser,dbpass)) + else: + dbclient = MongoClient('mongodb://mongo:27017/') return dbclient From e810771935047567d225b47d11ae6f4539d3f98e Mon Sep 17 00:00:00 2001 From: Rick Kauffman Date: Wed, 25 May 2022 12:33:24 -0700 Subject: [PATCH 7/7] fixed dbuser language in the README.md --- stackstorm-morpheus/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stackstorm-morpheus/README.md b/stackstorm-morpheus/README.md index b3c136e1..ed9f820a 100644 --- a/stackstorm-morpheus/README.md +++ b/stackstorm-morpheus/README.md @@ -50,14 +50,15 @@ Orquestra Workflows: will have a dash. ## Mongo considerations If your mongo instance does not have auth enabled, then you don't need to -provide a dbuser and dbpass +provide a dbuser and dbpass. If it is you can set the dbuser and dbpass +in the StackStorm GUI by navigating to the packs management page. If the default mongoDB is used and it has authentication enabled, you will need to create a new user and a database. This can be done by logging in as admin using the following example. -mongo -u admin -p admin +mongo -u admin -p admin ### Then create a new user db.createUser({user: "appUser",pwd: "passwordForAppUser",roles: [ { role: "readWrite", db: "app_db" } ]})