Skip to content

Commit

Permalink
add more columns to downtimes/comments_with_info
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Jan 24, 2025
1 parent 91cab14 commit a088d62
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 19 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ This file documents the revision history for the Livestatus Multitool Daemon (LM

next:
- use fallback addresses only if all primary fail
- add more columns to downtimes_with_info
- add more columns to comments_with_info

2.3.0 Thu Jan 16 08:20:30 CET 2025
- use primary key index for all tables
Expand Down
68 changes: 49 additions & 19 deletions pkg/lmd/datarow.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,15 +602,20 @@ func VirtualColMembersWithState(dRow *DataRow, _ *Column) interface{} {
}

// VirtualColCommentsWithInfo returns list of comment IDs with additional information.
func VirtualColCommentsWithInfo(d *DataRow, _ *Column) interface{} {
commentsStore := d.DataStore.DataSet.tables[TableComments]
commentsTable := commentsStore.Table
authorCol := commentsTable.GetColumn("author")
commentCol := commentsTable.GetColumn("comment")
comments := d.GetInt64ListByName("comments")
func VirtualColCommentsWithInfo(row *DataRow, _ *Column) interface{} {
comments := row.GetInt64ListByName("comments")
if len(comments) == 0 {
return emptyInterfaceList
}

commentsStore := row.DataStore.DataSet.tables[TableComments]
commentsTable := commentsStore.Table
authorCol := commentsTable.GetColumn("author")
commentCol := commentsTable.GetColumn("comment")
entryTimeCol := commentsTable.GetColumn("entry_time")
entryTypeCol := commentsTable.GetColumn("entry_type")
expiresCol := commentsTable.GetColumn("expires")
expireTimeCol := commentsTable.GetColumn("expire_time")
res := make([]interface{}, 0)
for idx := range comments {
commentID := fmt.Sprintf("%d", comments[idx])
Expand All @@ -620,23 +625,38 @@ func VirtualColCommentsWithInfo(d *DataRow, _ *Column) interface{} {

continue
}
commentWithInfo := []interface{}{comments[idx], comment.GetString(authorCol), comment.GetString(commentCol)}
commentWithInfo := []interface{}{
comments[idx],
comment.GetString(authorCol),
comment.GetString(commentCol),
comment.GetInt64(entryTimeCol),
comment.GetInt(entryTypeCol),
comment.GetInt(expiresCol),
comment.GetInt64(expireTimeCol),
}
res = append(res, commentWithInfo)
}

return res
}

// VirtualColDowntimesWithInfo returns list of downtimes IDs with additional information.
func VirtualColDowntimesWithInfo(d *DataRow, _ *Column) interface{} {
downtimesStore := d.DataStore.DataSet.tables[TableDowntimes]
downtimesTable := downtimesStore.Table
authorCol := downtimesTable.GetColumn("author")
commentCol := downtimesTable.GetColumn("comment")
downtimes := d.GetInt64ListByName("downtimes")
func VirtualColDowntimesWithInfo(row *DataRow, _ *Column) interface{} {
downtimes := row.GetInt64ListByName("downtimes")
if len(downtimes) == 0 {
return emptyInterfaceList
}

downtimesStore := row.DataStore.DataSet.tables[TableDowntimes]
downtimesTable := downtimesStore.Table
authorCol := downtimesTable.GetColumn("author")
commentCol := downtimesTable.GetColumn("comment")
entryTimeCol := downtimesTable.GetColumn("entry_time")
startTimeCol := downtimesTable.GetColumn("start_time")
endTimeCol := downtimesTable.GetColumn("end_time")
fixedCol := downtimesTable.GetColumn("fixed")
durationCol := downtimesTable.GetColumn("duration")
triggeredCol := downtimesTable.GetColumn("triggered_by")
res := make([]interface{}, 0)
for idx := range downtimes {
downtimeID := fmt.Sprintf("%d", downtimes[idx])
Expand All @@ -646,19 +666,29 @@ func VirtualColDowntimesWithInfo(d *DataRow, _ *Column) interface{} {

continue
}
downtimeWithInfo := []interface{}{downtimes[idx], downtime.GetString(authorCol), downtime.GetString(commentCol)}
downtimeWithInfo := []interface{}{
downtimes[idx],
downtime.GetString(authorCol),
downtime.GetString(commentCol),
downtime.GetInt64(entryTimeCol),
downtime.GetInt64(startTimeCol),
downtime.GetInt64(endTimeCol),
downtime.GetInt64(fixedCol),
downtime.GetInt64(durationCol),
downtime.GetInt64(triggeredCol),
}
res = append(res, downtimeWithInfo)
}

return res
}

// VirtualColCustomVariables returns a custom variables hash.
func VirtualColCustomVariables(d *DataRow, _ *Column) interface{} {
namesCol := d.DataStore.GetColumn("custom_variable_names")
valuesCol := d.DataStore.GetColumn("custom_variable_values")
names := d.dataStringList[namesCol.Index]
values := d.dataStringList[valuesCol.Index]
func VirtualColCustomVariables(row *DataRow, _ *Column) interface{} {
namesCol := row.DataStore.GetColumn("custom_variable_names")
valuesCol := row.DataStore.GetColumn("custom_variable_values")
names := row.dataStringList[namesCol.Index]
values := row.dataStringList[valuesCol.Index]
res := make(map[string]string, len(names))
for i := range names {
res[names[i]] = values[i]
Expand Down

0 comments on commit a088d62

Please sign in to comment.