Infoblox Exchange Cybersecurity Roadshow 2020 – Join us!
North America | Europe | Middle East/Africa | Asia-Pacific

Security

Reply

C# WAPI return_fields Problem

MWüthrich
Techie
Posts: 2
4433     0

Hello 
I would like to see the extensible_attributes of a specific hostrecord.
Unfortunately i don't find a way to display them using C#.NET.

I try the following:

<code>
public DataSet GetAllHostRecords()
            {
                string url = "https://%IPADDR%/wapi/v1.1/record:host?_return_type=xml-pretty";
                WebRequest request = WebRequest.Create(url);
                request.ContentType = "application/json";
                request.Method = "GET";
                request.Credentials = new NetworkCredential("%USER%", "%PASSWORD%");
                ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
                WebResponse response = request.GetResponse();
                Stream stream = response.GetResponseStream();
                StreamReader sr = new StreamReader(stream);
                string Message = sr.ReadToEnd();
                sr.Close();
                string xmlData = Message;
                DataSet myDS = new DataSet();
                byte[] buffer = Encoding.UTF8.GetBytes(xmlData);
                using (MemoryStream mystream = new MemoryStream(buffer))
                {
                    XmlReader reader = XmlReader.Create(mystream);
                    myDS.ReadXml(reader);
                }
                return myDS;
            }
</code>
 
I can Display all received objects in a datagridview. (No Problem so far).
I select one of the hosts in my gridview to display its settings with the following method:
(Example ReferenceID: record:host/ZG5zLmhvc3QkLm5vbl9ETlNfaG9zdF9yb290LmNvbS5ydWFnLnJpbnRyYS5jaDFzNTA0Mi1tMQ:hostname.domain/%20)
<code>
 public string GetHostByReference(string ReferenceID)
            {
                string url = "https://%IPADDR%wapi/v1.0/" + ReferenceID;
                WebRequest request = WebRequest.Create(url);
                request.ContentType = "application/json";
                request.Method = "GET";
                request.Credentials = new NetworkCredential("%USER%", "%PASSWORD%");
                ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
                WebResponse response = request.GetResponse();
                Stream stream = response.GetResponseStream();
                StreamReader sr = new StreamReader(stream);
                string Message = sr.ReadToEnd();              
                MessageBox.Show(Message);
                sr.Close();
                return Message;
            }
</code>
That method returns the information like this:
{
    "_ref": "record:host/ZG5zLmhvc3QkLm5vbl9ETlNfaG9zdF9yb290LmNoMXMxMzA4:%HOSTNAM%/%20", 
    "ipv4addrs": [
        {
            "_ref": "record:host_ipv4addr/ZG5zL.......
            "configure_for_dhcp": false, 
            "host": "%Hostname%", 
            "ipv4addr": "%IPAddr%"
        }
    ], 
    "name": "%Hostname%", 
    "view": " "
}

My Problem is now how do i display the extensible attributes for that host?

Thanks for your help

Re: C# WAPI return_fields

kcrozier
Techie
Posts: 1
4434     0

Hi Mike,

You need to add -d _return_fields= (with the name of the EA fields you want returned) to the GET

Ken Crozier

Sn. Technical Marketing Engineer

Re: C# WAPI return_fields

MWüthrich
Techie
Posts: 2
4434     0

Hi

Thanks for your reply

I was able to read the comment of a host record with the _return_fields option as follows:

<code>
 public string GetHostByReference(string ReferenceID)
            {
                string url = "https://%IPADDR%wapi/v1.0/" + ReferenceID + "?_return_fields=comment"
                WebRequest request = WebRequest.Create(url);
                request.ContentType = "application/json";
                request.Method = "GET";
                request.Credentials = new NetworkCredential("%USER%", "%PASSWORD%");
                ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
                WebResponse response = request.GetResponse();
                Stream stream = response.GetResponseStream();
                StreamReader sr = new StreamReader(stream);
                string Message = sr.ReadToEnd();              
                MessageBox.Show(Message);
                sr.Close();
                return Message;
            }
</code>
 
This now returns:
{
    "_ref": "record:host/ZG5zLmhvc3QkLm5vbl9ETlN........", 
    "comment": "BlaBla"
}

Entering the name of an Extensible Attribute as Example "OS" which is in that case Linux is still failing.

I tried the following which was working with the comment

 string url = "https://%IPADDR%wapi/v1.0/" + ReferenceID + "?_return_fields=OS"
 
Thanks for your help
 

Setting Extensible Attributes using the WAPI?

PLussier
Techie
Posts: 9
4434     0

How does one set the Extensible Attributes using the WAPI ?  I've tried the following:

curl -k3 -u admin:admin -H "Content-Type: application/json"-X POST https://192.168.1.2/wapi/v1.2/network -d '{"comment": "Foo Network", "network": "192.168.10.0/24", "extensible_attributes": {"Site": "Chicago Office"} }'

which fails.  Simply removing the "extensible_attributes" stuff allows the network to be created, but I can't seem to set the "Site" field, which shows up in the Extensible Attributes section.  Any ideas?

 

you can't get individual EAs,

GHorne Community Manager
Community Manager
Posts: 248
4434     0

you can't get individual EAs, you just have to return all of them:

_return_fields+=extattrs

the EA struct looks like this

GHorne Community Manager
Community Manager
Posts: 248
4434     0

the EA struct looks like this :

 {

   "extattrs": {

      "Site": { "value": "East" }

   }

 }

Showing results for 
Search instead for 
Do you mean 

Recommended for You