Skip to content

Commit

Permalink
feat: Show media type type human-readable string in table (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
pederhan authored Dec 4, 2024
1 parent dfb6d09 commit e1ae03c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion zabbix_cli/pyzabbix/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 20 additions & 6 deletions zabbix_cli/pyzabbix/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"]
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit e1ae03c

Please sign in to comment.