diff --git a/.circleci/config.yml b/.circleci/config.yml index a5a5a23..296bab9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 92f54fd..1f56116 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/README.md b/README.md index 198baa7..2227b73 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/actions/host_get_active_triggers.yaml b/actions/host_get_active_triggers.yaml new file mode 100644 index 0000000..1735e49 --- /dev/null +++ b/actions/host_get_active_triggers.yaml @@ -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: [] \ No newline at end of file diff --git a/actions/host_get_alerts.yaml b/actions/host_get_alerts.yaml new file mode 100644 index 0000000..c1b23a3 --- /dev/null +++ b/actions/host_get_alerts.yaml @@ -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 diff --git a/actions/host_get_events.yaml b/actions/host_get_events.yaml new file mode 100644 index 0000000..66243b6 --- /dev/null +++ b/actions/host_get_events.yaml @@ -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 diff --git a/actions/host_get_hostgroups.py b/actions/host_get_hostgroups.py new file mode 100644 index 0000000..d82e998 --- /dev/null +++ b/actions/host_get_hostgroups.py @@ -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 diff --git a/actions/host_get_hostgroups.yaml b/actions/host_get_hostgroups.yaml new file mode 100644 index 0000000..d4b5e24 --- /dev/null +++ b/actions/host_get_hostgroups.yaml @@ -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 \ No newline at end of file diff --git a/actions/host_get_triggers.yaml b/actions/host_get_triggers.yaml new file mode 100644 index 0000000..96b3998 --- /dev/null +++ b/actions/host_get_triggers.yaml @@ -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 diff --git a/actions/lib/actions.py b/actions/lib/actions.py index def7611..d7102bd 100644 --- a/actions/lib/actions.py +++ b/actions/lib/actions.py @@ -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)) @@ -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']) @@ -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'])) diff --git a/actions/workflows/host_get_active_triggers.yaml b/actions/workflows/host_get_active_triggers.yaml new file mode 100644 index 0000000..14b2a40 --- /dev/null +++ b/actions/workflows/host_get_active_triggers.yaml @@ -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 diff --git a/pack.yaml b/pack.yaml index 75deae3..685e79c 100644 --- a/pack.yaml +++ b/pack.yaml @@ -5,7 +5,7 @@ description: Zabbix Monitoring System keywords: - zabbix - monitoring -version: 1.0.0 +version: 1.2.4 author: Hiroyasu OHYAMA email: user.localhost2000@gmail.com python_versions: diff --git a/requirements.txt b/requirements.txt index cf48552..3c6485e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -py-zabbix==1.1.3 -st2client +git+https://github.com/EncoreTechnologies/py-zabbix.git pytz tzlocal