Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added get_events and get_alarms st2 actions #4

Merged
merged 3 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
Current status : Alpha
Version : 0.1.0
-initial release

Version : 0.1.1
-Added get events and get alarms actions
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# stackstorm-hpe-cfm
Current status: Alpha
Version : 0.1.0
Version : 0.1.1


HPE Composable Fabric stackstorm pack
Expand Down Expand Up @@ -33,5 +33,3 @@ Edit this file to have the appropriate data for the CFM you need to access.
Save the file and issue: `st2 key load system-settings.json`

Now these variable can be accessed in actions by using "{{ st2kv.system.ipaddress }}"


83 changes: 83 additions & 0 deletions actions/get_alarms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# (C) Copyright 2019 Hewlett Packard Enterprise Development LP.

# 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"
# __version__ = "1.0.0"
# __maintainer__ = "Rick Kauffman"
# __email__ = "rick.a.kauffman@hpe.com"

import json
from pyhpecfm.auth import CFMClient
from pyhpecfm import system
from st2common.runners.base_action import Action

class alarmLookup(Action):
def run(self, ipaddress=None, username=None, password=None):

# Create client connection
client = CFMClient(ipaddress, username, password)


try:
cfm_audits = system.get_audit_logs(client)
except:
error = "ERR-LOGIN - Failed to log into CFM controller"
return error

# Create a empty list for alarms
alarm_data = []

# Set some counters
c = 0
x = 0

# Loop through cfm_audits and process ALARMS

for i in cfm_audits:

try:
typex = cfm_audits[c]['record_type']
except:
typex = '-'

if typex == 'ALARM':

try:
eventType = cfm_audits[c]['data']['event_type']
except:
eventType = '-'

try:
sev = cfm_audits[c]['severity']
except:
sev = '-'

try:
desc = cfm_audits[c]['description']
except:
desc = '-'

# Build dictionary to add to list
out = {
'u_eventType': eventType,
'u_typex': typex,
'u_sev': sev,
'u_desc': desc
}
alarm_data.append(out)

c = c + 1
return (True, alarm_data)
26 changes: 26 additions & 0 deletions actions/get_alarms.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: get_alarms
pack: hpecfm
description: Get an array of alarms from the plexxi controller
runner_type: python-script
entry_point: get_alarms.py
enabled: true
parameters:
ipaddress:
type: "string"
description: "The IP address of a plexxi controller"
required: true
position: 0
default: "{{ st2kv.system.ipaddress }}"
username:
type: "string"
description: "The username to log into a plexxi controller"
required: true
position: 1
default: "{{ st2kv.system.username }}"
password:
type: "string"
description: "The password to a plexxi controller"
required: true
position: 2
default: "{{ st2kv.system.password }}"
94 changes: 94 additions & 0 deletions actions/get_events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# (C) Copyright 2019 Hewlett Packard Enterprise Development LP.

# 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"
# __version__ = "1.0.0"
# __maintainer__ = "Rick Kauffman"
# __email__ = "rick.a.kauffman@hpe.com"

import json
from pyhpecfm.auth import CFMClient
from pyhpecfm import system
from st2common.runners.base_action import Action

class eventLookup(Action):
def run(self, ipaddress=None, username=None, password=None):

# Create client connection
client = CFMClient(ipaddress, username, password)


try:
cfm_audits = system.get_audit_logs(client)
except:
error = "ERR-LOGIN - Failed to log into CFM controller"
return error

# Create a empty list for alarms
event_data = []

# Set some counters
c = 0
x = 0

# Loop through cfm_audits and process ALARMS
for i in cfm_audits:

try:
typex = cfm_audits[c]['record_type']
except:
typex = '-'

if typex == 'EVENT':

try:
eventType = cfm_audits[c]['data']['event_type']
except:
eventType = '-'

try:
objectName = cfm_audits[c]['data']['object_name']
except:
objectName = '-'

try:
objectType = cfm_audits[c]['data']['object_type']
except:
objectType = '-'

try:
sev = cfm_audits[c]['severity']
except:
sev = '-'

try:
desc = cfm_audits[c]['description']
except:
desc = '-'

# Build dictionary to add to list
out = {
'u_eventType': eventType,
'u_typex': typex,
'u_sev': sev,
'u_desc': desc,
'u_name' : objectName,
'u_typeo' : objectType
}
event_data.append(out)

c = c + 1
return (True, event_data)
26 changes: 26 additions & 0 deletions actions/get_events.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: get_events
pack: hpecfm
description: Get an array of events from the plexxi controller
runner_type: python-script
entry_point: get_events.py
enabled: true
parameters:
ipaddress:
type: "string"
description: "The IP address of a plexxi controller"
required: true
position: 0
default: "{{ st2kv.system.ipaddress }}"
username:
type: "string"
description: "The username to log into a plexxi controller"
required: true
position: 1
default: "{{ st2kv.system.username }}"
password:
type: "string"
description: "The password to a plexxi controller"
required: true
position: 2
default: "{{ st2kv.system.password }}"
2 changes: 1 addition & 1 deletion pack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: HPE Composable Fabric Integration Pack
keywords:
- Composable Fabric
- Plexxi
version: 0.1.0
version: 0.1.1
python_versions:
- "2"
- "3"
Expand Down