properties.adoc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. [#entity-properties]
  2. = Entity properties
  3. The `properties` field is configured on each entity definition in `config.yaml`. It does not live in the entity data files themselves.
  4. Use it to choose which fields from your entity data files are shown in the web UI and API. Property *values* come from the entity file on disk; `properties` only controls which of those values OliveTin exposes when listing or viewing entities.
  5. == Configuration
  6. Add `properties` under an entity definition alongside `file`, `name`, and `icon`:
  7. [source,yaml]
  8. ----
  9. entities:
  10. - file: /etc/OliveTin/servers.yaml
  11. name: server
  12. icon: ssh
  13. properties:
  14. - name: hostname
  15. title: Hostname
  16. - name: ip
  17. title: IP
  18. ----
  19. Each entry has two fields:
  20. [cols="1,3", options="header"]
  21. |===
  22. | Field | Description
  23. | `name`
  24. | The key to read from each entity instance in the data file. Matching is case-insensitive.
  25. | `title`
  26. | The column heading shown in the entity list table. If omitted, OliveTin uses `name`.
  27. |===
  28. The entity data file supplies the values. For example, with the configuration above and this data file:
  29. [source,yaml]
  30. .`/etc/OliveTin/servers.yaml`
  31. ----
  32. - name: server1
  33. hostname: server1.example.com
  34. ip: 192.168.0.1
  35. - name: server2
  36. hostname: server2.example.com
  37. ip: 192.168.0.2
  38. ----
  39. OliveTin shows `server1` and `server2` as instance names (from the `name` field) and displays `hostname` and `ip` in the configured columns.
  40. == Effects
  41. === Entity list in the web UI
  42. When `properties` is configured, the Entities page shows a searchable, paginated table for that entity type. Columns are:
  43. * **Name** — the instance title (derived from fields such as `name`, `title`, `hostname`, and so on)
  44. * One column per configured property, labelled with `title`
  45. When `properties` is omitted or empty, the Entities page shows a simple list of instance names and a total count instead of a table.
  46. === Entity details page
  47. The entity details view shows only the fields listed in `properties`, plus type and title.
  48. If `properties` is not configured, all top-level fields from the entity data file are shown.
  49. === API responses
  50. `properties` controls which fields appear in `fields` on entity instances returned by the API:
  51. * `GetEntity` — returns only configured property values in `fields` when `properties` is set; otherwise returns all top-level fields from the data file.
  52. * `GetEntities` — always includes the property definitions on `EntityDefinition`. When `properties` is set, instance rows in list responses include only those configured fields. The unfiltered list request omits instance rows (it returns `totalInstances` only); use a filtered request with `entityType` to fetch paginated instances for the table view.
  53. Search and pagination on the entity list operate over instance titles and the configured property values.
  54. === What `properties` does not affect
  55. `properties` is a display and API filtering setting. It does **not** limit what you can use in action templates.
  56. Actions bound to an entity still have access to the full entity record through `{{ .CurrentEntity.field }}`, including fields you did not list under `properties`. See xref:args/templates.adoc[Templates in actions] and xref:action_customization/enabledExpression.adoc[Enabled Expression].
  57. Legacy template syntax such as `{{ server.hostname }}` is still migrated automatically to `{{ .CurrentEntity.hostname }}`.
  58. == Example
  59. This configuration pairs with the server data file shown above:
  60. [source,yaml]
  61. ----
  62. entities:
  63. - file: entities/servers.yaml
  64. name: server
  65. icon: ssh
  66. properties:
  67. - name: hostname
  68. title: Hostname
  69. - name: ip
  70. title: IP
  71. ----
  72. An action can still reference any field from the data file, even ones not listed in `properties`:
  73. [source,yaml]
  74. ----
  75. actions:
  76. - title: Wake server
  77. shell: wakeonlan {{ .CurrentEntity.ip }}
  78. entity: server
  79. ----
  80. == What's next?
  81. * xref:entities/yaml.adoc[YAML entity files] — format for entity data files
  82. * xref:entities/json.adoc[JSON entity files] — line-delimited JSON entity files
  83. * xref:entities/icons.adoc[Entity icons] — configure an icon for each entity type
  84. * xref:entities/intro.adoc[Entities] — overview of entities in OliveTin
  85. * xref:dashboards/entity-directories.adoc[Entity directories] — generate per-entity dashboards