properties.adoc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. === Entity details page
  48. The entity details view shows only the fields listed in `properties`, plus type. The instance name appears in the page title, not again in the field list.
  49. If `properties` is not configured, all top-level fields from the entity data file are shown.
  50. === API responses
  51. `properties` controls which fields appear in `fields` on entity instances returned by the API:
  52. * `GetEntity` — returns only configured property values in `fields` when `properties` is set; otherwise returns all top-level fields from the data file.
  53. * `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.
  54. Search and pagination on the entity list operate over instance titles and the configured property values.
  55. === What `properties` does not affect
  56. `properties` is a display and API filtering setting. It does **not** limit what you can use in action templates.
  57. 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].
  58. Legacy template syntax such as `{{ server.hostname }}` is still migrated automatically to `{{ .CurrentEntity.hostname }}`.
  59. == Example
  60. This configuration pairs with the server data file shown above:
  61. [source,yaml]
  62. ----
  63. entities:
  64. - file: entities/servers.yaml
  65. name: server
  66. icon: ssh
  67. properties:
  68. - name: hostname
  69. title: Hostname
  70. - name: ip
  71. title: IP
  72. ----
  73. An action can still reference any field from the data file, even ones not listed in `properties`:
  74. [source,yaml]
  75. ----
  76. actions:
  77. - title: Wake server
  78. shell: wakeonlan {{ .CurrentEntity.ip }}
  79. entity: server
  80. ----
  81. == What's next?
  82. * xref:entities/yaml.adoc[YAML entity files] — format for entity data files
  83. * xref:entities/json.adoc[JSON entity files] — line-delimited JSON entity files
  84. * xref:entities/icons.adoc[Entity icons] — configure an icon for each entity type
  85. * xref:entities/intro.adoc[Entities] — overview of entities in OliveTin
  86. * xref:dashboards/entity-directories.adoc[Entity directories] — generate per-entity dashboards