<template name="netbox_data_opengear" results="per_template">
<doc>
Template to parse Opengear configuration and produce data structure
that is easy to work with to import data into the Netbox.

This template requires output of `config -g config` command.
</doc>

<input>
commands = [
    "config -g config"
]
platform = [
    "linux", # Netmiko
]
</input>

<macro>
def process_interface(data):
    from ttp_templates.utils.netbox_parse_opengear_config import process_interface

    return process_interface(data)
    
def process_output(data):
    from ttp_templates.utils.netbox_parse_opengear_config import process_output
    
    return process_output(data)
</macro>

## ------------------------------------------------------------------------------------------
## Global Configuration facts
## ------------------------------------------------------------------------------------------
<group name="facts**" method="table">
config.name {{ hostname }}
config.system.name {{ hostname }}
</group>

## ------------------------------------------------------------------------------------------
## DNS Servers configuration
## ------------------------------------------------------------------------------------------
<group name="nameservers*" method="table">
config.interfaces.lan.dns1 {{ name_server }}
</group>

## ------------------------------------------------------------------------------------------
## Logging configuration
## ------------------------------------------------------------------------------------------
<group name="logging**.{{ server }}" method="table">
config.syslog.servers.{{ server }}.address {{ host }}
</group>

## ------------------------------------------------------------------------------------------
## Users configuration
## ------------------------------------------------------------------------------------------
<group name="users*">
config.users.user1.username {{ username | joinmatches }}
</group>

## ------------------------------------------------------------------------------------------
## AAA configuration
## ------------------------------------------------------------------------------------------
<group name="aaa**" method="table">
config.auth.tacacs.auth_server {{ tacacs_servers | split(",") }}
config.auth.type {{ authentication_login }}
</group>

## ------------------------------------------------------------------------------------------
## NTP configuration
## ------------------------------------------------------------------------------------------
<group name="ntp">
config.ntp.servers.server1.address {{ server | joinmatches }}
</group>

## ------------------------------------------------------------------------------------------
## Interfaces configuration
## ------------------------------------------------------------------------------------------
<group name="interfaces**.{{ name }}**" functions="macro('process_interface')" method="table">
config.interfaces.{{ name }}.address {{ ipv4 }}
config.interfaces.{{ name }}.netmask {{ maskv4 }}
config.interfaces.{{ name }}.failover.address1 {{ failover_ip }}
config.interfaces.{{ name }}.failover.interface {{ failover_interface }}
config.interfaces.{{ name }}.gateway {{ gateway }}
config.interfaces.{{ name }}.mtu {{ mtu | to_int }}
config.interfaces.{{ name }}.disabled {{ disabled | default("off") }}
</group>

## ------------------------------------------------------------------------------------------
## Console Server Ports Configuration
## ------------------------------------------------------------------------------------------
<group name="console_server_ports**.{{ name }}**" method="table">
config.ports.{{ name }}.charsize {{ charsize }}
config.ports.{{ name }}.flowcontrol {{ flowcontrol }}
config.ports.{{ name }}.label {{ description | re(".+") }}
config.ports.{{ name }}.parity {{ parity }}
config.ports.{{ name }}.pinout {{ pinout }}
config.ports.{{ name }}.speed {{ speed }}
config.ports.{{ name }}.stop {{ stop_bits }}
</group>

## ------------------------------------------------------------------------------------------
## DHCP configuration
## ------------------------------------------------------------------------------------------
<group name="dhcprelay**" method="table">
config.services.dhcprelay.enabled {{ dhcprelay_enabled }}
config.services.dhcprelay.lowers.lower1.circuit_id {{ circuit_id }}
config.services.dhcprelay.lowers.lower1.role {{ client_ports }}
config.services.dhcprelay.servers.server1 {{ dhcp_server }}
<group name="uplink_ports*">
config.services.dhcprelay.uppers.upper1.interface {{ port | joinmatches }}
</group>
</group>

<output macro="process_output"/>

</template>
