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

Built-in content.table plugin #18

Closed
traut opened this issue Dec 31, 2023 · 2 comments
Closed

Built-in content.table plugin #18

traut opened this issue Dec 31, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@traut
Copy link
Member

traut commented Dec 31, 2023

Background

In addition to the installable plugins (#3), fabric must have built-in plugins to allow generation of simple content without the need to download extra components.

Related: #13, #15

Design

content.table plugin is a part of the fabric binary.

Specification

  • the plugin has no configuration options
  • API interface:
    • local context object
    • required columns attribute, a list of strings
    • optional datapoints attribute, a list of strings

Behavior

The plugin formats and returns a Markdown-formatted table with the header row.

The values in columns attribute are the column names. datapoints attribute contains a list of jq queries to be applied to every object in query_result object.

If query is not set, or datapoints is not set, or query_result is nil or an empty list, an empty table with the header is returned.

For example, with the content block

content table {
  query = <<-EOT
        data.elasticsearch.critical_alerts | (
            group_by(."kibana.alert.rule.name") |
            map({rule_name: .[0]."kibana.alert.rule.name", count: length})
        )
    EOT

  columns    = ["Rule Name", "Alerts Count"]
  datapoints = [".rule_name", ".count"]
}

and with the query_result set to

[
  {
    "rule_name": "Rule A",
    "count": 11
  },
  {
    "rule_name": "Rule B",
    "count": 22
  }
]

the expected result table would be

|Rule Name|Alerts Count|
|-|-|
|Rule A|11|
|Rule B|22|

Deliverables

  • new built-in content.table plugin
  • unit test for the plugin
@traut traut added enhancement New feature or request plugins labels Dec 31, 2023
@traut traut added this to the v0.1 milestone Dec 31, 2023
This was referenced Dec 31, 2023
@dobarx dobarx self-assigned this Jan 16, 2024
@dobarx
Copy link
Contributor

dobarx commented Jan 16, 2024

Updated specs

  • columns & datapoints bindings described together using single object with header & value properties.
  • use go templates instead of jq for row cels
  • header can also use go template literals and access all data context.

Example

columns = [{
   header = "Rule Name" 
   value = "{{.rule_name}}"
}, {
   header = "Alerts Count ({{.total_alerts}})" 
   value = "{{.count}}"
}]

@traut
Copy link
Member Author

traut commented Jan 17, 2024

implemented in #44

@traut traut closed this as completed Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants