Skip to content

Commit

Permalink
Merge pull request #62 from EncoreTechnologies/hotfix/fix-ci-errors
Browse files Browse the repository at this point in the history
feature/zabbix-6-support-and-more-actions
  • Loading branch information
nzlosh authored Feb 19, 2025
2 parents 5dfbc6f + 314510f commit 949c564
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 13 deletions.
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

0 comments on commit 949c564

Please sign in to comment.