diff --git a/CHANGELOG b/CHANGELOG index c734c39f..4bf0c138 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - `create_notification_user`: Now adds users to the default user group in addition to the notification user group to match behavior in V2. +- `show_media_types`: Now shows the formatted string representation of the media type `type` field instead of an integer. ### Deprecated diff --git a/zabbix_cli/pyzabbix/enums.py b/zabbix_cli/pyzabbix/enums.py index 44f8ccd5..64036891 100644 --- a/zabbix_cli/pyzabbix/enums.py +++ b/zabbix_cli/pyzabbix/enums.py @@ -112,7 +112,7 @@ def __fmt_name__(cls) -> str: def from_prompt( cls: Type[MixinType], prompt: Optional[str] = None, - default: MixinType = ..., + default: Any = ..., ) -> MixinType: """Prompt the user to select a choice from the enum. @@ -400,6 +400,16 @@ class MaintenanceWeekType(APIStrEnum): LAST_WEEK = APIStr("last week", 5) +class MediaTypeType(APIStrEnum): + """Type of media type.""" + + EMAIL = APIStr("email", 0) + SCRIPT = APIStr("script", 1) + SMS = APIStr("SMS", 2) + WEBHOOK = APIStr("webhook", 4) + # no 3 value in API + + class MonitoredBy(APIStrEnum): # >=7.0 only SERVER = APIStr("server", 0) PROXY = APIStr("proxy", 1) diff --git a/zabbix_cli/pyzabbix/types.py b/zabbix_cli/pyzabbix/types.py index 94715b15..eb2d65f8 100644 --- a/zabbix_cli/pyzabbix/types.py +++ b/zabbix_cli/pyzabbix/types.py @@ -16,7 +16,6 @@ import logging from datetime import datetime from datetime import timedelta -from typing import TYPE_CHECKING from typing import Any from typing import Dict from typing import Iterable @@ -46,6 +45,8 @@ from typing_extensions import TypeAliasType from typing_extensions import TypedDict +from zabbix_cli.models import ColsRowsType +from zabbix_cli.models import RowsType from zabbix_cli.models import TableRenderable from zabbix_cli.output.style import Color from zabbix_cli.pyzabbix.enums import AckStatus @@ -61,6 +62,7 @@ from zabbix_cli.pyzabbix.enums import MaintenancePeriodType from zabbix_cli.pyzabbix.enums import MaintenanceStatus from zabbix_cli.pyzabbix.enums import MaintenanceWeekType +from zabbix_cli.pyzabbix.enums import MediaTypeType from zabbix_cli.pyzabbix.enums import MonitoredBy from zabbix_cli.pyzabbix.enums import MonitoringStatus from zabbix_cli.pyzabbix.enums import ProxyCompatibility @@ -77,11 +79,6 @@ from zabbix_cli.utils.utils import get_maintenance_status from zabbix_cli.utils.utils import get_monitoring_status -if TYPE_CHECKING: - from zabbix_cli.models import ColsRowsType - from zabbix_cli.models import RowsType - - logger = logging.getLogger(__name__) SortOrder = Literal["ASC", "DESC"] @@ -843,6 +840,23 @@ class MediaType(ZabbixAPIBaseModel): type: int description: Optional[str] = None + @computed_field + @property + def type_str(self) -> str: + return MediaTypeType.string_from_value(self.type) + + def __cols_rows__(self) -> ColsRowsType: + cols = ["ID", "Name", "Type", "Description"] + rows: RowsType = [ + [ + self.mediatypeid, + self.name, + self.type_str, + self.description or "", + ] + ] + return cols, rows + class UserMedia(ZabbixAPIBaseModel): """Media attached to a user object."""