netbox-chart icon indicating copy to clipboard operation
netbox-chart copied to clipboard

YAML parsing of additional config doesn't allow for markdown new lines

Open ybizeul opened this issue 2 years ago • 1 comments

I'm adding a ConfigMap to the namespace for DEFAULT_DASHBOARD declaration, it looks like this :

apiVersion: v1
kind: ConfigMap
metadata:
  name: netbox-extra
  namespace: netbox
data:
  default-dashboard.yaml: |
    DEFAULT_DASHBOARD: [
      {
        'widget': 'extras.NoteWidget',
        'width': 3,
        'height': 2,
        'title': 'Shortcuts',
        'config': {
            'content':"**Racks Visualization**: [Front](/dcim/rack-elevations/?status=active) | [Rear](/dcim/rack-elevations/?status=active&face=rear)  
    **Lab Devices**: [Hardware](/dcim/devices/) | [VMs](/virtualization/virtual-machines/)  
    **IP Addresses**: [VLAN 760](/ipam/prefixes/1/ip-addresses/) | [VLAN 800](/ipam/prefixes/3/ip-addresses/) | [VLAN 790](/ipam/prefixes/2/ip-addresses/)"
        }
      },
    ]

Note that one line 15, I add two blank space " " which means "Got to next line" in markdown.

I think when python parses the yaml of the ConfigMap, it doesn't use the string as-is and does some funky stuff.

The only thing I managed to do was to add two blank line, but that creates a new markdown paragraph, instead of going to next line.

Note 1 Strictly using the dashboard UI in NetBox to create a note block and going to next line with the double space syntax does work correctly.

Note 2 If I strictly follow the example on NetBox documentation, is doesn't work at all as the parenthesis string literals in python don't play well with yaml :

    {
        'widget': 'extras.NoteWidget',
        'width': 4,
        'height': 2,
        'title': 'Welcome!',
        'color': 'green',
        'config': {
            'content': (
                'This is your personal dashboard. Feel free to customize it by rearranging, resizing, or removing '
                'widgets. You can also add new widgets using the "add widget" button below. Any changes affect only '
                '_your_ dashboard, so feel free to experiment!'
            )
        }
    },

Note 3 First thing I tried is using the | pipe yaml string literal to try and make a non escaped multi line paragraph :

apiVersion: v1
kind: ConfigMap
metadata:
  name: netbox-extra
  namespace: netbox
data:
  default-dashboard.yaml: |
    DEFAULT_DASHBOARD: [
      {
        'widget': 'extras.NoteWidget',
        'width': 3,
        'height': 2,
        'title': 'Shortcuts',
        'config': {
            'content':|
              **Racks Visualization**: [Front](/dcim/rack-elevations/?status=active) | [Rear](/dcim/rack-elevations/?status=active&face=rear)  
              **Lab Devices**: [Hardware](/dcim/devices/) | [VMs](/virtualization/virtual-machines/)  
              **IP Addresses**: [VLAN 760](/ipam/prefixes/1/ip-addresses/) | [VLAN 800](/ipam/prefixes/3/ip-addresses/) | [VLAN 790](/ipam/prefixes/2/ip-addresses/)"
        }
      },
    ]

But it doesn't seem python yaml.safe_load() is interpreting this correctly and leads to exceptions in the logs :

in "/run/config/extra/..2023_08_03_21_07_49.1217131338/default-dashboard.yaml", line 8, column 19

ybizeul avatar Aug 03 '23 21:08 ybizeul

Remember that the example you pointed at is actually Python code; your snippet should use valid YAML. The python code looks a little like JSON (which is valid YAML) but the quoting is wrong. I haven't actually tried this, but this is valid YAML at least:

apiVersion: v1
kind: ConfigMap
metadata:
  name: netbox-extra
  namespace: netbox
data:
  default-dashboard.yaml: |-
    DEFAULT_DASHBOARD:
      - widget: extras.NoteWidget
        width: 3
        height: 2
        title: Shortcuts
        config:
          content: |-
            **Racks Visualization**: [Front](/dcim/rack-elevations/?status=active) | [Rear](/dcim/rack-elevations/?status=active&face=rear)
            **Lab Devices**: [Hardware](/dcim/devices/) | [VMs](/virtualization/virtual-machines/)
            **IP Addresses**: [VLAN 760](/ipam/prefixes/1/ip-addresses/) | [VLAN 800](/ipam/prefixes/3/ip-addresses/) | [VLAN 790](/ipam/prefixes/2/ip-addresses/)

Please give this a go, and if you continue to get exceptions please post the full stack trace.

bootc avatar Nov 04 '23 23:11 bootc

Closing as stale, and with proper support provided already. @ybizeul Don't hesitate to reopen if this is still an issue.

LeoColomb avatar Jun 13 '24 16:06 LeoColomb