Skip to content

Commit e1ae03c

Browse files
authored
feat: Show media type type human-readable string in table (#266)
1 parent dfb6d09 commit e1ae03c

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Changed
1313

1414
- `create_notification_user`: Now adds users to the default user group in addition to the notification user group to match behavior in V2.
15+
- `show_media_types`: Now shows the formatted string representation of the media type `type` field instead of an integer.
1516

1617
### Deprecated
1718

zabbix_cli/pyzabbix/enums.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def __fmt_name__(cls) -> str:
112112
def from_prompt(
113113
cls: Type[MixinType],
114114
prompt: Optional[str] = None,
115-
default: MixinType = ...,
115+
default: Any = ...,
116116
) -> MixinType:
117117
"""Prompt the user to select a choice from the enum.
118118
@@ -400,6 +400,16 @@ class MaintenanceWeekType(APIStrEnum):
400400
LAST_WEEK = APIStr("last week", 5)
401401

402402

403+
class MediaTypeType(APIStrEnum):
404+
"""Type of media type."""
405+
406+
EMAIL = APIStr("email", 0)
407+
SCRIPT = APIStr("script", 1)
408+
SMS = APIStr("SMS", 2)
409+
WEBHOOK = APIStr("webhook", 4)
410+
# no 3 value in API
411+
412+
403413
class MonitoredBy(APIStrEnum): # >=7.0 only
404414
SERVER = APIStr("server", 0)
405415
PROXY = APIStr("proxy", 1)

zabbix_cli/pyzabbix/types.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import logging
1717
from datetime import datetime
1818
from datetime import timedelta
19-
from typing import TYPE_CHECKING
2019
from typing import Any
2120
from typing import Dict
2221
from typing import Iterable
@@ -46,6 +45,8 @@
4645
from typing_extensions import TypeAliasType
4746
from typing_extensions import TypedDict
4847

48+
from zabbix_cli.models import ColsRowsType
49+
from zabbix_cli.models import RowsType
4950
from zabbix_cli.models import TableRenderable
5051
from zabbix_cli.output.style import Color
5152
from zabbix_cli.pyzabbix.enums import AckStatus
@@ -61,6 +62,7 @@
6162
from zabbix_cli.pyzabbix.enums import MaintenancePeriodType
6263
from zabbix_cli.pyzabbix.enums import MaintenanceStatus
6364
from zabbix_cli.pyzabbix.enums import MaintenanceWeekType
65+
from zabbix_cli.pyzabbix.enums import MediaTypeType
6466
from zabbix_cli.pyzabbix.enums import MonitoredBy
6567
from zabbix_cli.pyzabbix.enums import MonitoringStatus
6668
from zabbix_cli.pyzabbix.enums import ProxyCompatibility
@@ -77,11 +79,6 @@
7779
from zabbix_cli.utils.utils import get_maintenance_status
7880
from zabbix_cli.utils.utils import get_monitoring_status
7981

80-
if TYPE_CHECKING:
81-
from zabbix_cli.models import ColsRowsType
82-
from zabbix_cli.models import RowsType
83-
84-
8582
logger = logging.getLogger(__name__)
8683

8784
SortOrder = Literal["ASC", "DESC"]
@@ -843,6 +840,23 @@ class MediaType(ZabbixAPIBaseModel):
843840
type: int
844841
description: Optional[str] = None
845842

843+
@computed_field
844+
@property
845+
def type_str(self) -> str:
846+
return MediaTypeType.string_from_value(self.type)
847+
848+
def __cols_rows__(self) -> ColsRowsType:
849+
cols = ["ID", "Name", "Type", "Description"]
850+
rows: RowsType = [
851+
[
852+
self.mediatypeid,
853+
self.name,
854+
self.type_str,
855+
self.description or "",
856+
]
857+
]
858+
return cols, rows
859+
846860

847861
class UserMedia(ZabbixAPIBaseModel):
848862
"""Media attached to a user object."""

0 commit comments

Comments
 (0)