Menu

How to extract data from TeemIP to feed it to Kea DHCPserver

Aas
2022-06-13
2022-08-03
  • Aas

    Aas - 2022-06-13

    Hello All
    I'm wondering how can I get list of all IP addresses in one specific subnet, along with MAC address of a corresponding device via REST API, so I can feed this data as reservations to Kea DHCP server? Kea accepts configuration in JSON format, so this should be straightforward, but i just don't know how.
    I have a reservations block in Kea with actual reservations included from file in JSON format like:

    {
        "hw-address": "00:11:22:33:44:55",
        "ip-address": "10.0.0.1"
    }
    

    So can you please give me an advice what json_data I have to post to REST API to get a list of these two values?

     
  • Xtophe38

    Xtophe38 - 2022-06-15

    Hi,

    I'm afraid that you won't be able to get the info through a simple REST/JSON request. Based on the datamodel (that you'll need to carefully look at) , you should be able to:

    • query the list of IP addresses contained in a given range,
    • query the list of devices attached to these IPs together with their MAC address.

    A way to go is to let TeemIp create part of the dhcpd configuration file(s) (like what is done to build the DNS db file) and allow users to get them through the REST/JSON API. But I'd need to go through a specification exercise first.

     
  • Aas

    Aas - 2022-06-15

    Hmmm. I'm not sure I understand how to "let TeemIp create dhcpd configuraion files".
    That's what am I aiming for.
    But as I understand it, there is no such function in TeemIP which can generate configuration for dhcpd or at least some parts which can be used as snippets to automate dhcpd configuration.
    I was thinking that RES/JSON API might be the way to use TeemIp as DDI solution with the Kea dhcp server which is configured through JSON files.
    Can you please correct my view?

     
  • Xtophe38

    Xtophe38 - 2022-06-15

    Your view is correct.
    But, as TeemIp editor, I had the 'dhcpd creation tool' as a long term objective. Since work toward that goal is significant, there might be intermediate steps that could be helpful (like listing the reservations or aggregating the different options of a pool... all in dhcpd.conf format).

     
  • Aas

    Aas - 2022-06-16

    But, if I'd like to use data from TeemIp to feed Kea dhcp server? At least address reservations, which needs just value pairs of MAC address and assigned IP address. Is it possible to get this information via REST/JSON API? The documentation of operations/classes/keys needs some work I think. How can I retrieve this MAC/IP value pairs with REST?
    I don't mind to do some background script to modify the output JSON so Kea can use it.

     
  • Xtophe38

    Xtophe38 - 2022-06-16

    It is definitely possible. But you'll probably need to retrieve the info in 2 steps:

    • get the list of IP addresses contained in a given range,
    • get the list of devices attached to these IPs together with their MAC address.

    TeemIp REST/JSON web services are described here. They rely on iTop REST/JSON web services that are described here.

     
  • Aas

    Aas - 2022-06-17

    Thank you for your patience with me.
    Finally I was able to grasp what classes I can use in REST query from Administration > Universal Search > Search for [Combo Box] and came up with something like this

    http://teemip.example.com/webservices/rest.php?version=1.2&json_data={ "operation": "core/get","class":"PC", "key": "SELECT PC", "output_fields":"name,macaddress,ipaddress_id_friendlyname"}
    

    The only downside is that I get only one type of device. (In this case PCs).
    Is there a way I can get all devices (PCs, Servers, ...) at once?

     
  • Xtophe38

    Xtophe38 - 2022-06-17

    You need to browse the Data Model available from the Administration menu to better understand the structure of the different classes

    As you'll see, MAC addresses usually appear in the final class of a CI. As a consequence, a "SELECT PhysicalDevice" or "SELECT ConnectableCI" won't wok. You'll need to run one query per class.

     
  • Aas

    Aas - 2022-07-28

    Thank you very much Chris. This works okay.
    One more thing I'd like to ask.
    Now, the Kea server pulls data from TeemIP every minute, even when there are no changes in the database. Is there a way to push the data from TeemIP to Kea when a change occurs, rather than pull it from Kea server constantly?

     
  • Xtophe38

    Xtophe38 - 2022-08-03

    This could be done through the "WebHook Integration" extension which is documented here. The extension can be retrieved for free from iTop Hub and automatically installed within your iTop or manually installed if you use TeemIp standalone. Note that next TeemIp revision should include that extension.

    Drawback is that you'll need to develop a small web application that offers an API where your scripts will be called from.

     

Log in to post a comment.

MongoDB Logo MongoDB