Uploaded image for project: 'OpenNMS'
  1. OpenNMS
  2. NMS-12625

Description: Cannot create monitored-service with JSON via ReST

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: Meridian-2019.1.4, 25.2.1
    • Fix Version/s: Meridian-2019.1.5, 26.0.0
    • Component/s: REST
    • Security Level: Default (Default Security Scheme)
    • Labels:
      None

      Description

      A customer expressed a special requirement to avoid any kind of auto-discover and or scan/walk interface tables for specific equipment.

      To solve this problem, the idea is to use the ReST API to populate the inventory.

      The usage of the ReST APIv1 with XML was suggested for consistency, as not all the end-points work with JSON.

      Interestingly, JSON is the default in APIv2, but some end-points don't work well with it, so for meta-data, also XML was suggested.

      Here are some examples of what fails:

      APIv2 Problems
      [root@meridian2019 ~]# curl -v -u admin:admin -H 'Content-Type: application/json' -d '{"status":"A","serviceType":{"name":"HTTP"}}' http://localhost:8980/opennms/api/v2/nodes/3/ipinterfaces/10.0.0.1/services
      *   Trying ::1...
      * TCP_NODELAY set
      * Connected to localhost (::1) port 8980 (#0)
      * Server auth using Basic with user 'admin'
      > POST /opennms/api/v2/nodes/3/ipinterfaces/10.0.0.1/services HTTP/1.1
      > Host: localhost:8980
      > Authorization: Basic YWRtaW46YWRtaW4=
      > User-Agent: curl/7.61.1
      > Accept: */*
      > Content-Type: application/json
      > Content-Length: 44
      >
      * upload completely sent off: 44 out of 44 bytes
      < HTTP/1.1 500 Server Error
      < Date: Wed, 25 Mar 2020 19:08:16 GMT
      < X-Frame-Options: SAMEORIGIN
      < Content-Type: text/plain
      < Content-Length: 174
      < Server: Jetty(9.4.18.v20190429)
      <
      * Connection #0 to host localhost left intact
      Can not handle managed/back reference 'defaultReference': back reference type (java.util.Set) not compatible with managed type (org.opennms.netmgt.model.OnmsMonitoredService)
      
      [root@meridian2019 ~]# curl -v -u admin:admin -H 'Content-Type: application/xml' -d '<service status="A"><serviceType><name>HTTP</name></serviceType></service>' http://localhost:8980/opennms/api/v2/nodes/3/ipinterfaces/10.0.0.1/services
      *   Trying ::1...
      * TCP_NODELAY set
      * Connected to localhost (::1) port 8980 (#0)
      * Server auth using Basic with user 'admin'
      > POST /opennms/api/v2/nodes/3/ipinterfaces/10.0.0.1/services HTTP/1.1
      > Host: localhost:8980
      > Authorization: Basic YWRtaW46YWRtaW4=
      > User-Agent: curl/7.61.1
      > Accept: */*
      > Content-Type: application/xml
      > Content-Length: 77
      >
      * upload completely sent off: 77 out of 77 bytes
      < HTTP/1.1 201 Created
      < Date: Wed, 25 Mar 2020 19:09:25 GMT
      < X-Frame-Options: SAMEORIGIN
      < Location: http://localhost:8980/opennms/api/v2/nodes/3/ipinterfaces/10.0.0.1/services/HTTP
      < Content-Length: 0
      < Server: Jetty(9.4.18.v20190429)
      <
      * Connection #0 to host localhost left intact
      

      As you can see, using XML works but not JSON.

      APIv1 Problems
      [root@meridian2019 ~]# curl -v -u admin:admin -H 'Content-Type: application/json' -d '{"status":"A","serviceType":{"name":"HTTPS"}}' http://localhost:8980/opennms/rest/nodes/3/ipinterfaces/10.0.0.1/services
      *   Trying ::1...
      * TCP_NODELAY set
      * Connected to localhost (::1) port 8980 (#0)
      * Server auth using Basic with user 'admin'
      > POST /opennms/rest/nodes/3/ipinterfaces/10.0.0.1/services HTTP/1.1
      > Host: localhost:8980
      > Authorization: Basic YWRtaW46YWRtaW4=
      > User-Agent: curl/7.61.1
      > Accept: */*
      > Content-Type: application/json
      > Content-Length: 45
      >
      * upload completely sent off: 45 out of 45 bytes
      < HTTP/1.1 415 Unsupported Media Type
      < Date: Wed, 25 Mar 2020 19:11:10 GMT
      < X-Frame-Options: SAMEORIGIN
      < Content-Length: 0
      < Server: Jetty(9.4.18.v20190429)
      <
      * Connection #0 to host localhost left intact
      
      [root@meridian2019 ~]# curl -v -u admin:admin -H 'Content-Type: application/xml' -d '<service status="A"><serviceType><name>HTTPS</name></serviceType></service>' http://localhost:8980/opennms/rest/nodes/3/ipinterfaces/10.0.0.1/services
      *   Trying ::1...
      * TCP_NODELAY set
      * Connected to localhost (::1) port 8980 (#0)
      * Server auth using Basic with user 'admin'
      > POST /opennms/rest/nodes/3/ipinterfaces/10.0.0.1/services HTTP/1.1
      > Host: localhost:8980
      > Authorization: Basic YWRtaW46YWRtaW4=
      > User-Agent: curl/7.61.1
      > Accept: */*
      > Content-Type: application/xml
      > Content-Length: 75
      >
      * upload completely sent off: 75 out of 75 bytes
      < HTTP/1.1 201 Created
      < Date: Wed, 25 Mar 2020 19:11:55 GMT
      < X-Frame-Options: SAMEORIGIN
      < Location: http://localhost:8980/opennms/rest/nodes/3/ipinterfaces/10.0.0.1/services/HTTPS
      < Content-Length: 0
      < Server: Jetty(9.4.18.v20190429)
      <
      * Connection #0 to host localhost left intact
      

      Similarly XML works. Although, the problem here seems to be MIME-Type, which is easy to fix.

      I'm attaching the stack trace of the exception when using APIv2 for monitored-services.

      Fortunately, creating nodes, IP Interfaces, and SNMP interfaces work with JSON on APIv2.

      Unfortunately, that is not the case for APIv1. The problem is also "Unsupported Media Type".

        Attachments

          Activity

            People

            Assignee:
            patrick.schweizer Patrick Schweizer
            Reporter:
            agalue Alejandro Galue
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: