13 Replies Latest reply on Mar 17, 2016 4:56 PM by azabielski

    REST API Creating Nodes

    azabielski

      So i am able to consume the API and it does create the node and update the properties how i want however the Caption field is not required and it doesn't ever seem to auto populate also it doesn't seem to ever properly poll or automatically add resources needed.

       

      How can i make sure it does a poll and update the caption with the hostname?

       

      How can i set resources or all discovered resources to be added to monitor?

        • Re: REST API Creating Nodes
          tdanner

          Can you post your script?

            • Re: REST API Creating Nodes
              azabielski

              Yes of course sorry.

               

                      // POST call/nodes

                      public HttpResponseMessage Post([FromBody]NodeInfo info)

                      {

                          CustomNodeInfo cnInfo = new CustomNodeInfo();

                          #region Hard Coded Values for SaaS

                          //Hard coding these for now as this is for just the SaaS Poller currently

                          info.EngineID = 4;

                          cnInfo.CRM_Account = "AN_CUST1099";

                          cnInfo.ACCPAC_SiteID = "MST-SaaS";

                          cnInfo.AssetType = "Server";

               

               

                          ModelState.Remove("value.EngineID");

                          //End Hard Coded

                          #endregion

               

               

                          info.EntityType = "Orion.Nodes";

                          info.DynamicIP = false;

                          info.Status = 1;

                          info.UnManaged = false;

                          info.Allow64BitCounters = false;

                          if (ModelState.IsValid)

                          {

                              string query = "{\"query\":\"SELECT PropertyValue FROM Orion.EngineProperties WHERE EngineID=@e AND PropertyName='Orion.Standard.Polling'\",\"parameters\":{\"e\":"+info.EngineID+"}}";

               

               

                              JObject pollingRate = JObject.Parse(SWJsonCall.Post("Json/Query", query));

               

               

                              int curRate = (Int32)pollingRate["results"][0]["PropertyValue"];

                              if (curRate < 85)

                              {

                                  //Create Node First

                                  string createNode = SWJsonCall.Post("Json/Create/Orion.Nodes", JsonConvert.SerializeObject(info));

                                  //Make the returned swis url nice

                                  createNode = createNode.Replace("\\","").Replace("\"","");

                                  string updateProps = SWJsonCall.Post("Json/" + createNode + "/CustomProperties", JsonConvert.SerializeObject(cnInfo));

               

               

                                  return new HttpResponseMessage(HttpStatusCode.Created);

                              }

                              else

                              {

                                  return Request.CreateResponse(HttpStatusCode.InternalServerError, "Polling rate at dangerous level " + curRate + "%. Please consult Admins, node NOT added.");

                              }

                          }

                          else

                          {

                              var message = string.Join(" | ", ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage));

                              var execption = string.Join(" | ", ModelState.Values.SelectMany(v => v.Errors).Select(e => e.Exception));

                              return Request.CreateResponse(HttpStatusCode.BadRequest, "Error - " + message + " : " + execption);

                          }

                      }