Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEXT_FIELDS #42

Open
daniloltec opened this issue Mar 3, 2023 · 22 comments
Open

TEXT_FIELDS #42

daniloltec opened this issue Mar 3, 2023 · 22 comments

Comments

@daniloltec
Copy link

I'm having trouble finding the text_fields to customize the labels in the cables section.
I'm not able to pull device A or B, only the ports.

'cable': {
'text_fields':['a_terminations', 'a_device', 'b_terminations', ''],
},

Is there any library to fetch these text fields?

@abdurrm
Copy link

abdurrm commented Jul 13, 2023

you can use this fields:

 'cable': {
            'text_fields': [
                'a_terminations.device',
                'a_terminations',
                'b_terminations.device',
                'b_terminations'
                ]
        }

@Lord-ZuzurNC
Copy link

Hello,

I'm confused here. You state 'a_terminations.device' where the Install process of the plugin says:

{'text_fields': ['_termination_a_device', 'termination_a', '_termination_b_device', 'termination_b',]}

@Lord-ZuzurNC
Copy link

Lord-ZuzurNC commented Aug 29, 2023

I am adding more on this conversation (as its name state only 'text_fields'):

I have, for example for the racks, this config:

        'rack': {
            'text_fields': [
                'name',
                'role',
                'location',
                'site',
                'tenant'
            ]
        },

Saved and restart the netbox services.

Just so you see I completed the attribute in Netbox:
image

But the QR Code only shows its name.
image

@k01ek
Copy link
Collaborator

k01ek commented Aug 29, 2023

You can use only text fields of object. Role, location, site, tenant are not text fields, this fields are Object type. If you need those fields you can use text_template:
text_template: '{{ obj.name }} {{ obj.site }} ...etc'

@Lord-ZuzurNC
Copy link

Lord-ZuzurNC commented Aug 29, 2023

Hmmm I'm sorry I'm absolutely new to J2 and so still can't understand yet all the things about it.

I tried, lets take an example for the site:

  • {{ obj.site }}
  • {{ dcim.site }}
  • {{ obj.dcim.site }}

But can't get the data I only have that rack name on it even if I didn't put the name object on my text_templates.

Also I put 'text_template' in the rack sub-bracket and in the root netbox-qrcode bracket (not in the same time, I commented one while using the other one) but still I only got the rack name...
I even changed the font to ComicSanMS to see if anything applies but got same font as above screen. So nothing is applied from the PLUGINS_CONFIG for QR Code.

I am obviously doing something wrong but can't get what... (sorry I'm temporarily in japan due to time zone I may reply late)

That's my whole plugin config:

    'netbox-qrcode': {
        'with_text': True,
#        'text_fields': ['name', 'serial'],
#        'text_template': '{{ obj.site }}',
#        'font': 'CourierNewBold',
        'font': 'ComicSanMS',
        'custom_text': 'Property of someOne\nTel: +aCertainNumber',
        'text_location': 'up',
        'qr_version': 1,
        'qr_error_correction': 2,
        'qr_box_size': 6,
        'qr_border': 4,
        'cable': {
            'text_fileds': [
                'id',
                'label',
                '_termination_a_device',
                'termination_a',
                '_termination_b_device',
                'termination_b'
            ]
        },
#        'rack': {
#            'text_template': '{{ obj.name }} {{ obj.role }} {{ obj.location }} {{ obj.site }} {{ obj.tenant }}'
#            'text_template': '{{ obj.site }}'
#            'text_template': '{{ dcim.site }}'
#        },
        'device': {
            'text_fields': [
                'name',
                'ip_address',
                'role',
                'manufacturer',
                'type',
                'rack',
                'location',
                'site',
                'tenant'
            ]
        }
    }

@k01ek
Copy link
Collaborator

k01ek commented Aug 29, 2023

I don't know what are you doing wrong, but its work for me:
{ 'with_text': True, 'text_fields': ['name', 'serial'], 'font': 'TahomaBold', 'custom_text': None, 'text_location': 'right', 'qr_version': 1, 'qr_error_correction': 0, 'qr_box_size': 6, 'qr_border': 4, 'device': { 'text_fields': ['name', 'serial'], 'text_template': 'http://localhost:8000{{ obj.get_absolute_url }}' }, 'rack': { 'text_fields': ['name'], 'text_template': '{{ obj.site }}\n{{ obj.tenant }}' }, 'cable': { 'text_fields': [ '_termination_a_device', 'termination_a', '_termination_b_device', 'termination_b', 'a_terminations.device', 'a_terminations', 'b_terminations.device', 'b_terminations' ] }, 'location': { 'text_fields': ['name'], 'text_template': '{{ obj.site }}' } }

@Lord-ZuzurNC
Copy link

Lord-ZuzurNC commented Aug 29, 2023

I backed up my conf and imported yours to try it.
I still have the same misbehavior.

Do I need to do something else than modifying the configuration.py and restart the netbox service?
I tried to do manage.py migrate but "netbox_qrcode does not have migrations". (I also cleared my cache browser and used InPrivate just in case).

@k01ek
Copy link
Collaborator

k01ek commented Aug 29, 2023

PLUGINS_CONFIG = {
'netbox_qrcode': {
'with_text': True,
'text_fields': ['name', 'serial'],
'font': 'ArialMT',
'custom_text': 'Property of SomeCompany\ntel.8.800333554-CALL',
'text_location': 'up',
'qr_version': 1,
'qr_error_correction': 0,
'qr_box_size': 4,
'qr_border': 4,
# per object options
'cable': None, # disable QR code for Cable object
'rack': {
'text_fields': [
'site',
'name',
'facility_id',
'tenant',
'cf.cf_name'
]
},
'device': {
'qr_box_size': 6,
'custom_text': None,
}
}
}

@k01ek
Copy link
Collaborator

k01ek commented Aug 29, 2023

PLUGINS_CONFIG = {
'netbox_qrcode': {

@Lord-ZuzurNC
Copy link

I feel stupid now.

That was the things... Thank you very much for your time and your eyes.
If someone read this and don't get it I used an hyphen "-" instead of an underscore "_" in the "netbox_qrcode" name.

Have a nice day/evening.

@k01ek
Copy link
Collaborator

k01ek commented Aug 29, 2023

You can use only text fields of object. Role, location, site, tenant are not text fields, this fields are Object type. If you need those fields you can use text_template:
text_template: '{{ obj.name }} {{ obj.site }} ...etc'

I was wrong, you also can use this fields if they can be represented as string

@Lord-ZuzurNC
Copy link

Lord-ZuzurNC commented Aug 29, 2023

Oh you're right I used text_template on rack and text_fields on location and both worked.

I am wondering how to name things like "Rack Role" or "Tenant Group".
I tried "tenant.group", "tenantgroup", "tenant-group" and "tenant_group" but no success. Maybe these are not usable?
Note that I tried on text_fields and assume they will have same behavior in template.

Maybe plurial? In "groups"?

Edit1: I tried with combination of no char, a dot, a hypen and a underscore and each of them with one then the other then both in plurial (tenants group / tenant groups / tenants groups). My next move is to try them in text_template instead of text_fields.

I just saw that on the readme there is already an example of a two word which is "Facility ID": 'facility_id'. So should be an underscore. stupid idea as Rack Role in the rack section is only 'role'.
I was wondering 'group' but how to do a difference between a tenant group and a site group?

EDIT2: BINGO
It is {{ obj.tenant.group }} and it only works as a text_template (not as a text_fields, or I didn't discovered the correct naming for it).
And it works for everyting if you want Rack Facility ID: {{ obj.facility.id }} and if you want the site facility: {{ obj.site.facility }} etc...

@dbrustad
Copy link

hi guys apologies if I missed the answer- In the devices category I have a network switch, and in netbox under the management heading there are status role platform etc, and what I want to place next to the barcode is the Primary IPv4 ipaddress. Any idea if I can display that?

@Lord-ZuzurNC
Copy link

hi guys apologies if I missed the answer- In the devices category I have a network switch, and in netbox under the management heading there are status role platform etc, and what I want to place next to the barcode is the Primary IPv4 ipaddress. Any idea if I can display that?

If you are in text_fields you should be able to use "ip_address".
In text_template you should use "{{ obj.ip.address }}"

@dbrustad
Copy link

thank you for such a fast reply! I tried both those options to no avail. using text template I can display out everything except ip address. Could it matter that primary ip is associated with a vlan?

@Lord-ZuzurNC
Copy link

Hmm I wonder... I will be able to test it today and give you an answer. But when I tried in Aug I created the whole chain and so my IP had a VLAN.

@Lord-ZuzurNC
Copy link

I agree with you.
I don't get the IPv4 on the QR code. I don't even have Device Type, Manufacturer, Device Role and IP Address.
I used obj.type, obj.manufacturer, obj.role, obj.ip.address which are apparently not the correct naming.
All other object works like obj.name, obj.platform, obj.rack, obj.location, obj.location.parent, obj.site, obj.site.facility, obj.tenant, obj.tenant.group and obj.site.region (all works well).

@dbrustad
Copy link

ok thank you for confirming! was also working on the links feature and there it would only accept object spelled out and not obj- but that has also changed over time. This is all quite confusing for a beginner to be sure. Anyway if anyone knows of a way to get the primary ip next to a device barcode please chime in

@Lord-ZuzurNC
Copy link

Lord-ZuzurNC commented Sep 22, 2023

Raah I tried really lots of combination and still can't figure out the ipv4...
tried lots of combo like (starting with "obj.") ipam.ipaddress.ipv4, ipam.ipv4, ipam.ipaddress, ip.address, ipaddress.ipv4, ip,ipv4, and lots more.

I even tried from this other issue

@BrunoMaiberg
Copy link

BrunoMaiberg commented Jan 18, 2024

Hi, i have the same problem when I try to use cables, it won't show Termination A and Termination B on the QR-CODE, just the QR-CODE itself, Rack, devices work just fine. but the cable, just the QR-CODE with a sample text that i used.

`PLUGINS_CONFIG = {
  'netbox_topology_views': {
    'device_img': 'router,switch,firewall',
    'preselected_device_roles': 'Router, Firewall',
    'allow_coordinates_saving': False,
    'ignore_cable_type': '',
  },
  'netbox_qrcode': {
    'with_text': True,
    'custom_text': '\nMaiberg.Tec            ',
    'text_fields': ['name', 'serial'],
    'font': 'ArialMT',
    'qr_version': 1,
    'qr_error_correction': 0,
    'qr_box_size': 4,
    'qr_border': 4,
    'cable': {
      'text_fields': [
        'termination_a.device',
        'termination_a',
        'termination_b.device',
        'termination_b',
      ]
    },
    'rack': {
      'text_fields': [
        'site',
        'name',
        'tenant'
      ]
    },
    'device': {
      'text_fields': [
        'name',
        'serial',
        'tenant',
        'primary_ip'
      ]
    }
  }
}`


Update: I figure it out how to do something useful
'cabletermination': { 'text_fields': [ 'cable', ] },

download

now i can put this on the cable to trace it

@aalleessaandrooo
Copy link

Does not generate qr code for cables, no error log.

SETTINGS:
'cable': {
'text_fileds': [
'site',
'name',
'id',
'label',
'_termination_a_device',
'termination_a',
'_termination_b_device',
'termination_b'
]
},

@aalleessaandrooo
Copy link

Hi, i have the same problem when I try to use cables, it won't show Termination A and Termination B on the QR-CODE, just the QR-CODE itself, Rack, devices work just fine. but the cable, just the QR-CODE with a sample text that i used.

`PLUGINS_CONFIG = {
  'netbox_topology_views': {
    'device_img': 'router,switch,firewall',
    'preselected_device_roles': 'Router, Firewall',
    'allow_coordinates_saving': False,
    'ignore_cable_type': '',
  },
  'netbox_qrcode': {
    'with_text': True,
    'custom_text': '\nMaiberg.Tec            ',
    'text_fields': ['name', 'serial'],
    'font': 'ArialMT',
    'qr_version': 1,
    'qr_error_correction': 0,
    'qr_box_size': 4,
    'qr_border': 4,
    'cable': {
      'text_fields': [
        'termination_a.device',
        'termination_a',
        'termination_b.device',
        'termination_b',
      ]
    },
    'rack': {
      'text_fields': [
        'site',
        'name',
        'tenant'
      ]
    },
    'device': {
      'text_fields': [
        'name',
        'serial',
        'tenant',
        'primary_ip'
      ]
    }
  }
}`

Update: I figure it out how to do something useful 'cabletermination': { 'text_fields': [ 'cable', ] },

download

now i can put this on the cable to trace it

Can you explain how it was resolved?
Where should I add the line: 'cabletermination': { 'text_fields': [ 'cable', ] },

Can you share your file with config?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants