What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Mailstore HHTP Post API: unsupported value type string for select

Votes:

0

Hi,

we want use the http API from Mailstore for monitoring. We tested the API with postman and get the answer:

{
  "error": null,
  "token": null,
  "statusVersion": 2,
  "statusCode": "succeeded",
  "percentProgress": null,
  "statusText": null,
  "result": [
    {
      "instanceID": "swr2021",
      "alias": "swr",
      "displayName": "Mailarchiv ",
      "instanceHost": "mailstore.test.de",
      "startMode": "automatic",
      "processID": 4492,
      "status": "running",
      "startStopError": null
    }
  ],
  "logOutput": null
}

Now we want ask for the "status" in prtg. Template file:

{
    "prtg": {
      "result": [
        {
          "channel": "Test" ,
          "value": lookup($.result.status, "running", "stopped")
        }
      ]
    }
  }

The value is a string, so we must convert it with lookup.

The prtg settings are:

  • Post
  • Post-Data: instanceFilter: swr2021
  • HTTPS
  • standard auth
  • HTTP Header: Content-Type: application/x-www-form-urlencoded
  • REST Request: :8474/api/invoke/GetInstances

But PRTG genereates an error: Could no evaluate channel value of Test: unsupported value type string for select, expected map[string]interface{} or []interface{}.

api json-template rest rest-costum-sensor

Created on Nov 30, 2021 4:01:10 PM



6 Replies

Votes:

0

Hello,

Thank you for your message.

To monitor the status provided in the JSON response, I invite you to use the following template (under "C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\rest"):

{
  "prtg": {	
    "result": [
      {
        "Value":{ "["+ #1 +"]" + " Status": $.result..({ @.displayName : lookup(@.status, "stopped", "running") }).*},
		"ValueLookup": "mailstore.status"
      }
     ]
  }
}

Then, you will need to create a new lookup file (ex: mailserver.ovl, under "C:\Program Files (x86)\PRTG Network Monitor\lookups\custom") which will convert the integer value into meaningful state:

<?xml version="1.0" encoding="UTF-8"?>
  <ValueLookup id="mailstore.status" desiredValue="1" undefinedState="Warning" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PaeValueLookup.xsd">
    <Lookups>
      <SingleInt state="Error" value="0">
        Stopped
      </SingleInt>
      <SingleInt state="Ok" value="1">
        Running
      </SingleInt>
    </Lookups>
  </ValueLookup>

When you have created it, make sure to reload the lookup files in PRTG by using the button under Setup > System Administration > Administrative Tools | Load Lookups and File Lists.


Here is the result you should get: Rest Custom sensor

Of course, you can modify the template or lookup as you need.

If you have questions, do not hesitate.

Regards.

Created on Dec 2, 2021 8:23:18 AM by  Florian Lesage [Paessler Support]

Last change on Dec 2, 2021 10:41:32 AM by  Florian Lesage [Paessler Support]



Votes:

0

Hi,

no channel in sensor. Only response time is showing.

Created on Dec 2, 2021 9:21:10 AM



Votes:

0

Thank you for the update.

Based on the JSON response you provided, the template should work properly therefore I suspect that a sensor setting might be incorrect. Can you please enable the logs of the sensor by selecting the option Store result in the settings tab and then check the files generated under [data path]\Logs\sensors where the data path is displayed in PRTG Administration Tool on the probe server.

Created on Dec 2, 2021 1:05:38 PM by  Florian Lesage [Paessler Support]

Last change on Dec 2, 2021 1:06:00 PM by  Florian Lesage [Paessler Support]



Votes:

0

Hi,

Result of Sensor.Data.txt

Data['jsonpath'].asString := 'MailstoreInstanceStatus.template';
Data['customheaders'].asString := 'Content-Type:application/x-www-form-urlencoded';
Data['fastcount'].asString := '0';
Data['query'].asString := ':8474/api/invoke/GetInstances';
Data['tlsexplicit_pop3'].asString := '';
Data['resultfile'].asString := 'Result of Sensor 4064.txt';
Data['resourceid'].asString := '';
Data['hostv6'].asString := '';
Data['notonpod'].asString := '0';
Data['lastuptime'].asString := '0';
Data['writeresult'].asString := '1';
Data['blockedsens'].asString := '';
Data['reqmsginterval'].asString := '60';
Data['lastmsg'].asString := '#P1';
Data['tlsexplicit_imap'].asString := '';
Data['tlsexplicit_default'].asString := '';
Data['channelnames'].asString := 'Antwortzeit'#$D#$A + 
'0'#$D#$A + 
'';
Data['canlinux'].asString := '0';
Data['isexesensor'].asString := '1';
Data['channelinfos'].asString := '{"0":{"Unit":"oukTimeResponse","CustomUnit":"","ValueLookupName":"","LimitMode":"0","LimitMinError":"","LimitMinWarning":"","LimitMaxError":"","LimitMaxWarning":""}}';
Data['proxypassword'].asString := '';
Data['uptimecount'].asString := '0';
Data['authuserpwd'].asString := '***';
Data['reboot'].asString := '44535.1643351042';
Data['usednstime'].asString := '0';
Data['authtoken'].asString := '';
Data['checkfailed'].asString := '0';
Data['requestbody'].asString := '"instanceFilter":"swr2021"';
Data['authmethod'].asString := '1';
Data['tlsexplicit_port'].asString := '';
Data['inerror'].asString := '0';
Data['sensorid'].asString := '4064';
Data['ipversion'].asString := '0';
Data['proxy'].asString := '';
Data['tlsexplicit_smtp'].asString := '';
Data['host'].asString := 'mailstore.swits.de';
Data['protocol'].asString := '1';
Data['tlsignore'].asString := '1';
Data['proxyuser'].asString := '';
Data['simulate'].asString := '0';
Data['timeout'].asString := '60';
Data['tlsexplicit_ftp'].asString := '';
Data['requesttype'].asString := '1';
Data['momopersistent'].asString := '';
Data['authusername'].asString := 'monitoring';

Result of Sensor.txt

{
  "prtg": {
    "result": [
      {
        "channelid": 0,
        "Value": 63,
        "Unit": "TimeResponse",
        "ShowChart": 0,
        "ShowTable": 0
      }
    ]
  }
}

Created on Dec 6, 2021 9:06:32 AM



Votes:

0

Hi,

Thank you for the sensor logs.

According to them, the channel is still not created whereas it should with the template provided. Have you created the sensor anew? If not, can you please do so and let me know if the result is the same.

I also invite you to execute the sensor directly by executing rest.exe located on the probe server under "C:\Program Files (x86)\PRTG Network Monitor\Sensor System" via a command prompt or a PowerShell console.

To use it, you need to provide the different information you configured in the sensor Settings tab by using the corresponding options listed here:

.\rest.exe URL TEMPLATE(full path) -post 1 -tlsignore 1 -customheader 'Content-Type:application/x-www-form-urlencoded' -requestbody '"instanceFilter":"swr2021"'

Which result do you get when you execute that command ?

Created on Dec 6, 2021 11:52:47 AM by  Florian Lesage [Paessler Support]

Last change on Dec 6, 2021 11:54:02 AM by  Florian Lesage [Paessler Support]



Votes:

0

Hi,

here is something strange. With the cmd comand same output:

PS C:\Program Files (x86)\PRTG Network Monitor\Sensor System> .\rest.exe  https://mailstore.swits.de:8474/api/invoke/GetInstances "C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\rest\MailstoreInstanceStatus.template" -authusername monitoring -authuserpwd *** -post 1 -tlsignore 1 -customheader 'Content-Type:application/x-www-form-urlencoded' -requestbody '"instanceFilter":"swr2021"'
{
  "prtg": {
    "result": [
      {
        "channelid": 0,
        "Value": 78,
        "Unit": "TimeResponse",
        "ShowChart": 0,
        "ShowTable": 0
      }
    ]
  }
}

Sensor rebuild three times, two server reboots.

MailstoreInstanceStatus.template

{
  "prtg": {	
    "result": [
      {
        "Value":{ "["+ #1 +"]" + " Status": $.result..({ @.displayName : lookup(@.status, "stopped", "running") }).*},
		"ValueLookup": "mailstore.status"
      }
     ]
  }
}

Mailstore.ovl

<?xml version="1.0" encoding="UTF-8"?>
  <ValueLookup id="mailstore.status" desiredValue="1" undefinedState="Warning" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PaeValueLookup.xsd">
    <Lookups>
      <SingleInt state="Error" value="0">
        stopped
      </SingleInt>
      <SingleInt state="Ok" value="1">
        running
      </SingleInt>
    </Lookups>
  </ValueLookup>

We use the XL1 licence. So is it better to open a support case for better comunication?

Created on Dec 6, 2021 2:13:38 PM




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.