This is a translation of the original English documentation page. Help us make it better.

mediatype.get

Omschrijving

integer/array mediatype.get(object parameters)

Deze methode maakt het mogelijk om mediatypen op te halen op basis van de opgegeven parameters.

Deze methode is beschikbaar voor gebruikers van elk type. Toestemmingen om de methode aan te roepen kunnen worden ingetrokken in de instellingen voor gebruikersrollen. Zie Gebruikersrollen voor meer informatie.

Parameters

(object) Parameters die de gewenste uitvoer definiëren.

De methode ondersteunt de volgende parameters.

Parameter Type Beschrijving
mediatypeids string/array Geef alleen media types terug met de opgegeven IDs.
mediaids string/array Geef alleen media types terug die worden gebruikt door de opgegeven media.
userids string/array Geef alleen media types terug die worden gebruikt door de opgegeven gebruikers.
selectMessageTemplates query Retourneer een message_templates eigenschap met een array van berichtsjablonen van het mediatype.
selectUsers query Retourneer een users eigenschap met de gebruikers die het mediatype gebruiken.
sortfield string/array Sorteer het resultaat op basis van de opgegeven eigenschappen.

Mogelijke waarden: mediatypeid.
countOutput boolean Deze parameters, die gebruikelijk zijn voor alle get methoden, worden in detail beschreven in het referentiecommentaar.
editable boolean
excludeSearch boolean
filter object
limit integer
output query
preservekeys boolean
search object
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch boolean

Retourwaarden

(integer/array) Retourneert ofwel:

  • een reeks objecten;
  • het aantal opgehaalde objecten, als de countOutput parameter heeft gebruikt.

Voorbeelden

Ophalen van mediatypen

Haal alle geconfigureerde mediatypen op. Het volgende voorbeeld geeft twee mediatypen terug:

  • E-mail mediatype;
  • SMS mediatype.

Verzoek:

{
           "jsonrpc": "2.0",
           "method": "mediatype.get",
           "params": {
               "output": "extend",
               "selectMessageTemplates": "extend"
           },
           "id": 1
       }

Reactie:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "mediatypeid": "1",
                   "type": "0",
                   "name": "E-mail",
                   "smtp_server": "mail.example.com",
                   "smtp_helo": "example.com",
                   "smtp_email": "[email protected]",
                   "exec_path": "",
                   "gsm_modem": "",
                   "username": "",
                   "passwd": "",
                   "status": "0",
                   "smtp_port": "25",
                   "smtp_security": "0",
                   "smtp_verify_peer": "0",
                   "smtp_verify_host": "0",
                   "smtp_authentication": "0",
                   "maxsessions": "1",
                   "maxattempts": "3",
                   "attempt_interval": "10s",
                   "content_type": "0",
                   "script": "",
                   "timeout": "30s",
                   "process_tags": "0",
                   "show_event_menu": "1",
                   "event_menu_url": "",
                   "event_menu_name": "",
                   "description": "",
                   "message_templates": [
                       {
                           "eventsource": "0",
                           "recovery": "0",
                           "subject": "Probleem: {EVENT.NAME}",
                           "message": "Probleem gestart om {EVENT.TIME} op {EVENT.DATE}\r\nProbleemnaam: {EVENT.NAME}\r\nHost: {HOST.NAME}\r\nErnst: {EVENT.SEVERITY}\r\nOperationele gegevens: {EVENT.OPDATA}\r\nOorspronkelijke probleem-ID: {EVENT.ID}\r\n{TRIGGER.URL}"
                       },
                       {
                           "eventsource": "0",
                           "recovery": "1",
                           "subject": "Opgelost: {EVENT.NAME}",
                           "message": "Probleem is opgelost om {EVENT.RECOVERY.TIME} op {EVENT.RECOVERY.DATE}\r\nProbleemnaam: {EVENT.NAME}\r\nHost: {HOST.NAME}\r\nErnst: {EVENT.SEVERITY}\r\n\r\nOorspronkelijke probleem-ID: {EVENT.ID}\r\n{TRIGGER.URL}"
                       },
                       {
                           "eventsource": "0",
                           "recovery": "2",
                           "subject": "Bijgewerkt probleem: {EVENT.NAME}",
                           "message": "{USER.FULLNAME} heeft probleem bijgewerkt op {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.\r\n{EVENT.UPDATE.MESSAGE}\r\n\r\nHuidige probleemstatus is {EVENT.STATUS}, erkend: {EVENT.ACK.STATUS}."
                       },
                       {
                           "eventsource": "1",
                           "recovery": "0",
                           "subject": "Ontdekking: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}",
                           "message": "Ontdekkingsregel: {DISCOVERY.RULE.NAME}\r\n\r\nApparaat-IP: {DISCOVERY.DEVICE.IPADDRESS}\r\nApparaat-DNS: {DISCOVERY.DEVICE.DNS}\r\nApparaatstatus: {DISCOVERY.DEVICE.STATUS}\r\nApparaat uptime: {DISCOVERY.DEVICE.UPTIME}\r\n\r\nServicenaam apparaat: {DISCOVERY.SERVICE.NAME}\r\nServicepoort apparaat: {DISCOVERY.SERVICE.PORT}\r\nServicestatus apparaat: {DISCOVERY.SERVICE.STATUS}\r\nService-uptime apparaat: {DISCOVERY.SERVICE.UPTIME}"
                       },
                       {
                           "eventsource": "2",
                           "recovery": "0",
                           "subject": "Autoregistratie: {HOST.HOST}",
                           "message": "Hostnaam: {HOST.HOST}\r\nHost-IP: {HOST.IP}\r\nAgentpoort: {HOST.PORT}"
                       }
                   ],
                   "parameters": []
               },
               {
                   "mediatypeid": "3",
                   "type": "2",
                   "name": "SMS",
                   "smtp_server": "",
                   "smtp_helo": "",
                   "smtp_email": "",
                   "exec_path": "",
                   "gsm_modem": "/dev/ttyS0",
                   "username": "",
                   "passwd": "",
                   "status": "0",
                   "smtp_port": "25",
                   "smtp_security": "0",
                   "smtp_verify_peer": "0",
                   "smtp_verify_host": "0",
                   "smtp_authentication": "0",
                   "maxsessions": "1",
                   "maxattempts": "3",
                   "attempt_interval": "10s",
                   "content_type": "1",
                   "script": "",
                   "timeout": "30s",
                   "process_tags": "0",
                   "show_event_menu": "1",
                   "event_menu_url": "",
                   "event_menu_name": "",
                   "description": "",
                   "message_templates": [
                       {
                           "eventsource": "0",
                           "recovery": "0",
                           "subject": "",
                           "message": "{EVENT.SEVERITY}: {EVENT.NAME}\r\nHost: {HOST.NAME}\r\n{EVENT.DATE} {EVENT.TIME}"
                       },
                       {
                           "eventsource": "0",
                           "recovery": "1",
                           "subject": "",
                           "message": "OPGELOST: {EVENT.NAME}\r\nHost: {HOST.NAME}\r\n{EVENT.DATE} {EVENT.TIME}"
                       },
                       {
                           "eventsource": "0",
                           "recovery": "2",
                           "subject": "",
                           "message": "{USER.FULLNAME} heeft probleem bijgewerkt op {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}"
                       },
                       {
                           "eventsource": "1",
                           "recovery": "0",
                           "subject": "",
                           "message": "Ontdekking: {DISCOVERY.DEVICE.STATUS} {DISCOVERY.DEVICE.IPADDRESS}"
                       },
                       {
                           "eventsource": "2",
                           "recovery": "0",
                           "subject": "",
                           "message": "Autoregistratie: {HOST.HOST}\r\nHost-IP: {HOST.IP}\r\nAgentpoort: {HOST.PORT}"
                       }
                   ],
                   "parameters": []
               }
           ],
           "id": 1
       }

Retrieving media types as Admin

As an Admin type user, retrieve all media types that are enabled, with users that use these media types. The following example returns two media types:

  • email media type with one user (since Zabbix 7.0.4, only Admin type user's own user);
  • SMS media type with no users.

Request:

{
           "jsonrpc": "2.0",
           "method": "mediatype.get",
           "params": {
               "output": "extend",
               "filter": {
                   "status": 0
               },
               "selectUsers": "extend"
           },
           "id": 1
       }

Response:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "mediatypeid": "1",
                   "type": "0",
                   "name": "Email",
                   "status": "0",
                   "description": "",
                   "maxattempts": "3",
                   "users": [
                       {
                           "userid": "3",
                           "username": "database-admin",
                           "name": "John",
                           "surname": "Doe",
                           "url": "",
                           "autologin": "0",
                           "autologout": "0",
                           "lang": "default",
                           "refresh": "30s",
                           "theme": "default",
                           "attempt_failed": "0",
                           "attempt_ip": "",
                           "attempt_clock": "0",
                           "rows_per_page": "50",
                           "timezone": "default",
                           "roleid": "2",
                           "userdirectoryid": "0",
                           "ts_provisioned": "0"
                       }
                   ]
               },
               {
                   "mediatypeid": "3",
                   "type": "2",
                   "name": "SMS",
                   "status": "0",
                   "description": "",
                   "maxattempts": "3",
                   "users": []
               }
           ],
           "id": 1
       }

Ophalen van script- en webhook-mediatypen

Het volgende voorbeeld geeft drie mediatypen terug:

  • script-mediatype met parameters;
  • script-mediatype zonder parameters;
  • webhook-mediatype met parameters.

Verzoek:

{
           "jsonrpc": "2.0",
           "method": "mediatype.get",
           "params": {
               "output": ["mediatypeid", "name", "parameters"],
               "filter": {
                   "type": [1, 4]
               }
           },
           "id": 1
       }

Reactie:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "mediatypeid": "10",
                   "name": "Script met parameters",
                   "parameters": [
                       {
                           "sortorder": "0",
                           "value": "{ALERT.SENDTO}"
                       },
                       {
                           "sortorder": "1",
                           "value": "{EVENT.NAME}"
                       },
                       {
                           "sortorder": "2",
                           "value": "{ALERT.MESSAGE}"
                       },
                       {
                           "sortorder": "3",
                           "value": "Zabbix waarschuwing"
                       }
                   ]
               },
               {
                   "mediatypeid": "13",
                   "name": "Script zonder parameters",
                   "parameters": []
               },
               {
                   "mediatypeid": "11",
                   "name": "Webhook",
                   "parameters": [
                       {
                           "name": "alert_message",
                           "value": "{ALERT.MESSAGE}"
                       },
                       {
                           "name": "event_update_message",
                           "value": "{EVENT.UPDATE.MESSAGE}"
                       },
                       {
                           "name": "host_name",
                           "value": "{HOST.NAME}"
                       },
                       {
                           "name": "trigger_description",
                           "value": "{TRIGGER.DESCRIPTION}"
                       },
                       {
                           "name": "trigger_id",
                           "value": "{TRIGGER.ID}"
                       },
                       {
                           "name": "alert_source",
                           "value": "Zabbix"
                       }
                   ]
               }
           ],
           "id": 1
       }

Zie ook

Bron

CMediaType::get() in ui/include/classes/api/services/CMediaType.php.