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

feature/zabbix-6-support-and-more-actions #62

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0864b8a
Merge pull request #5 from StackStorm-Exchange/master
bishopbm1 Apr 5, 2021
1a52fa1
Merge pull request #7 from StackStorm-Exchange/master
bishopbm1 Apr 5, 2022
4778622
adding actions to get alerts/events/triggers
asktheaxis Jun 28, 2022
21ff665
bumping pack version, adding actions to CHANGELOG & README
asktheaxis Jun 29, 2022
a4bdbe4
Merge pull request #8 from EncoreTechnologies/feature/alerts-events-t…
bishopbm1 Jul 6, 2022
9baa34b
adding workflow to get active triggers for a given host
asktheaxis Aug 22, 2022
cc08c46
adding changes/bumping version
asktheaxis Aug 22, 2022
391a19f
Merge pull request #9 from EncoreTechnologies/feature/active-triggers-wf
bishopbm1 Aug 23, 2022
3a7e6ff
adding param to active triggers wf so triggers can be filtered by sev…
asktheaxis Aug 26, 2022
d218bc8
adding changes to changelog and bumping version
asktheaxis Aug 26, 2022
526b864
spelling
asktheaxis Aug 26, 2022
9d045b5
Merge pull request #10 from EncoreTechnologies/update/active-triggers…
bishopbm1 Aug 26, 2022
c459f84
adding action to list hostgroups for host/check if host is in hostgro…
asktheaxis Sep 28, 2022
5d17b24
bumping version, adding to changes/readme
asktheaxis Sep 28, 2022
60cf53e
Merge pull request #11 from EncoreTechnologies/feature/hostgroups-get
bishopbm1 Oct 5, 2022
9084910
Updated py-zabbix module because the Zabbix API recently changed thei…
jschoewe Jun 6, 2023
83a07bb
Update requirements.txt
jschoewe Jun 6, 2023
a6b134c
Update requirements.txt
jschoewe Jun 6, 2023
eddd08a
Merge pull request #12 from EncoreTechnologies/update/zabbix-api-para…
bishopbm1 Jun 7, 2023
aa2814c
Bumped pack version
jschoewe Feb 17, 2025
314510f
Fixed files to work with latest CI updates
jschoewe Feb 17, 2025
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: 0 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ jobs:

workflows:
version: 2
integration_tests_on_push:
jobs:
- integration_test_with_zabbix_32
- integration_test_with_zabbix_40
circleci_is_disabled:
jobs:
- circleci_is_disabled_job
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# Change Log

## 1.2.4
### Updated
- Updated files to work with latest CI updates

## 1.2.3
### Updated
- Updated py-zabbix module because the Zabbix API recently changed their login parameters

## 1.2.2
### Added
- `actions/host_get_hostgroups` - Gets/Checks the hostgroups that a given Zabbix host is in

## 1.2.1
### Added
- `actions/workflows/host_get_active_triggers` - Added parameter, 'priority', which allows active triggers to be filtered by severity (priority) level

## 1.2.0
### Added
- `actions/workflows/host_get_active_triggers` - Gets active triggers for a given Zabbix host

## 1.1.0

### Added
- `actions/host_get_alerts` - Gets alerts for a given Zabbix host
- `actions/host_get_events` - Gets events for a given Zabbix host
- `actions/host_get_triggers` - Gets triggers for a given Zabbix host

## 1.0.0

- Drop python 2.7 support.
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,15 @@ You need to set configure the Zabbix pack before running actions:
| zabbix.ack_event | Send acknowledgement message for an event to Zabbix and if Zabbix may close it |
| zabbix.host_delete | Delete a Zabbix Host |
| zabbix.host_delete_by_id | Delete a Zabbix Host by it's Id |
| zabbix.host_get_alerts | Get events for a given Zabbix host |
| zabbix.host_get_events | Get events for a given Zabbix host |
| zabbix.host_get_hostgroups | Get/Check the hostgroups of a Zabbix Host |
| zabbix.host_get_id | Get the ID of a Zabbix Host |
| zabbix.host_get_inventory | Get the inventory of one or more Zabbix Hosts |
| zabbix.host_get_multiple_ids | Get the IDs of multiple Zabbix Hosts |
| zabbix.host_get_status | Get the status of a Zabbix Host |
| zabbix.host_get_triggers | Get triggers for a given Zabbix host |
| zabbix.host_get_active_triggers | Get active triggers for a given Zabbix host |
| zabbix.host_update_status | Update the status of a Zabbix Host |
| zabbix.maintenance_create_or_update | Create or update Zabbix Maintenance Window |
| zabbix.maintenance_delete | Delete Zabbix Maintenance Window |
Expand Down
17 changes: 17 additions & 0 deletions actions/host_get_active_triggers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
description: "List all active triggers for a given host"
enabled: true
runner_type: orquesta
entry_point: workflows/host_get_active_triggers.yaml
name: host_get_active_triggers
pack: zabbix
parameters:
host:
type: string
description: "Name of the Zabbix Host"
required: True
priority:
type: array
description: "List of priority numbers (severity) to get triggers for"
required: False
default: []
25 changes: 25 additions & 0 deletions actions/host_get_alerts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: host_get_alerts
pack: zabbix
runner_type: python-script
description: List all alerts for a given host ID in Zabbix
enabled: true
entry_point: call_api.py
parameters:
expandDescription:
type: string
description: "test flag"
default: ""
immutable: true
filter:
type: object
description: Condition to filter the result
token:
type: string
description: Encrypted access token to authenticate to ZabbixServer
default: |
{% if st2kv.user.zabbix.secret_token|string != '' %}{{ st2kv.user.zabbix.secret_token | decrypt_kv }}{% endif %}
secret: true
api_method:
default: alert.get
immutable: true
25 changes: 25 additions & 0 deletions actions/host_get_events.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: host_get_events
pack: zabbix
runner_type: python-script
description: List all events for a given host in Zabbix
enabled: true
entry_point: call_api.py
parameters:
expandDescription:
type: string
description: "test flag"
default: ""
immutable: true
filter:
type: object
description: Condition to filter the result
token:
type: string
description: Encrypted access token to authenticate to ZabbixServer
default: |
{% if st2kv.user.zabbix.secret_token|string != '' %}{{ st2kv.user.zabbix.secret_token | decrypt_kv }}{% endif %}
secret: true
api_method:
default: event.get
immutable: true
44 changes: 44 additions & 0 deletions actions/host_get_hostgroups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

from lib.actions import ZabbixBaseAction
from pyzabbix.api import ZabbixAPIException


class HostGetHostGroups(ZabbixBaseAction):

def run(self, host_id, group_id):
""" Gets the hostgroups of one or more Zabbix Hosts.
"""
self.connect()

# Find hostgroups by host ids
try:
hostgroups = self.client.host.get(
hostids=host_id, selectGroups='extend', output=['hostid', 'groups'])
except ZabbixAPIException as e:
raise ZabbixAPIException(("There was a problem searching for the host: "
"{0}".format(e)))

# if group ids are passed in we check to see if the host is a part of said groups
if group_id:
for group in hostgroups[0]["groups"]:
if group["groupid"] == group_id:
return hostgroups

return (False, hostgroups)
# otherwise just return the groups the host is in
else:
return hostgroups
16 changes: 16 additions & 0 deletions actions/host_get_hostgroups.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: host_get_hostgroups
pack: zabbix
runner_type: python-script
description: Gets/Checks the hostgroups of one or more Zabbix Hosts
enabled: true
entry_point: host_get_hostgroups.py
parameters:
group_id:
type: string
description: "Optional Group ID to check if host is in"
required: False
host_id:
type: string
description: "Host ID to find hostgroups for"
required: True
25 changes: 25 additions & 0 deletions actions/host_get_triggers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: host_get_triggers
pack: zabbix
runner_type: python-script
description: List all triggers for a given host in Zabbix
enabled: true
entry_point: call_api.py
parameters:
expandDescription:
type: string
description: "test flag"
default: ""
immutable: true
filter:
type: object
description: Condition to filter the result
token:
type: string
description: Encrypted access token to authenticate to ZabbixServer
default: |
{% if st2kv.user.zabbix.secret_token|string != '' %}{{ st2kv.user.zabbix.secret_token | decrypt_kv }}{% endif %}
secret: true
api_method:
default: trigger.get
immutable: true
12 changes: 6 additions & 6 deletions actions/lib/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def find_host(self, host_name):
zabbix_host = self.client.host.get(filter={"host": host_name})
except ZabbixAPIException as e:
raise ZabbixAPIException(("There was a problem searching for the host: "
"{0}".format(e)))
"{0}".format(e)))

if len(zabbix_host) == 0:
raise ValueError("Could not find any hosts named {0}".format(host_name))
Expand All @@ -77,7 +77,7 @@ def maintenance_get(self, maintenance_name):
return result
except ZabbixAPIException as e:
raise ZabbixAPIException(("There was a problem searching for the maintenance window: "
"{0}".format(e)))
"{0}".format(e)))

def maintenance_create_or_update(self, maintenance_params):
maintenance_result = self.maintenance_get(maintenance_params['name'])
Expand All @@ -87,16 +87,16 @@ def maintenance_create_or_update(self, maintenance_params):
return create_result
except ZabbixAPIException as e:
raise ZabbixAPIException(("There was a problem creating the "
"maintenance window: {0}".format(e)))
"maintenance window: {0}".format(e)))
elif len(maintenance_result) == 1:
try:
maintenance_id = maintenance_result[0]['maintenanceid']
update_result = self.client.maintenance.update(maintenanceid=maintenance_id,
**maintenance_params)
**maintenance_params)
return update_result
except ZabbixAPIException as e:
raise ZabbixAPIException(("There was a problem updating the "
"maintenance window: {0}".format(e)))
"maintenance window: {0}".format(e)))
elif len(maintenance_result) >= 2:
raise ValueError(("There are multiple maintenance windows with the "
"name: {0}").format(maintenance_params['name']))
"name: {0}").format(maintenance_params['name']))
53 changes: 53 additions & 0 deletions actions/workflows/host_get_active_triggers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
version: 1.0

description: List all active triggers for a given host

input:
- host
- priority

vars:
- error: ""
- triggers: []
- host_id: ""


output:
- triggers: "{{ ctx().triggers }}"

tasks:
get_zabbix_id:
action: zabbix.host_get_id
input:
host: "{{ ctx().host }}"
next:
- when: "{{ succeeded() }}"
publish:
- host_id: "{{ result().result }}"
do:
- get_triggers
- when: "{{ failed() }}"
publish:
- error: "{{ result().stderr }}"
do:
- fail

get_triggers:
action: zabbix.host_get_triggers
input:
filter:
hostid: "{{ ctx().host_id }}"
value: 1
priority: "{{ ctx().priority }}"
next:
- when: "{{ succeeded() }}"
publish:
- triggers: "{{ result().result }}"
do:
- noop
- when: "{{ failed() }}"
publish:
- error: "{{ result().stderr }}"
do:
- fail
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: Zabbix Monitoring System
keywords:
- zabbix
- monitoring
version: 1.0.0
version: 1.2.4
author: Hiroyasu OHYAMA
email: [email protected]
python_versions:
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
py-zabbix==1.1.3
st2client
git+https://github.com/EncoreTechnologies/py-zabbix.git
pytz
tzlocal
Loading