Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/humioctl/aggregate_alerts_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func newAggregateAlertsListCmd() *cobra.Command {
format.String(strings.Join(aggregateAlert.Labels, ", ")),
format.Bool(aggregateAlert.Enabled),
format.StringPtr(aggregateAlert.ThrottleField),
format.Int(aggregateAlert.ThrottleTimeSeconds),
format.Int(aggregateAlert.SearchIntervalSeconds),
format.Int64(aggregateAlert.ThrottleTimeSeconds),
format.Int64(aggregateAlert.SearchIntervalSeconds),
format.String(aggregateAlert.QueryTimestampType),
format.String(aggregateAlert.TriggerMode),
format.String(aggregateAlert.OwnershipRunAsID),
Expand Down
4 changes: 2 additions & 2 deletions cmd/humioctl/aggregate_alerts_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ func newAggregateAlertsShowCmd() *cobra.Command {
{format.String("Name"), format.String(aggregateAlert.Name)},
{format.String("Description"), format.StringPtr(aggregateAlert.Description)},
{format.String("Query String"), format.String(aggregateAlert.QueryString)},
{format.String("Search Interval Seconds"), format.Int(aggregateAlert.SearchIntervalSeconds)},
{format.String("Search Interval Seconds"), format.Int64(aggregateAlert.SearchIntervalSeconds)},
{format.String("Actions"), format.String(strings.Join(aggregateAlert.ActionNames, ", "))},
{format.String("Labels"), format.String(strings.Join(aggregateAlert.Labels, ", "))},
{format.String("Enabled"), format.Bool(aggregateAlert.Enabled)},
{format.String("Throttle Field"), format.StringPtr(aggregateAlert.ThrottleField)},
{format.String("Throttle Time Seconds"), format.Int(aggregateAlert.ThrottleTimeSeconds)},
{format.String("Throttle Time Seconds"), format.Int64(aggregateAlert.ThrottleTimeSeconds)},
{format.String("Query Timestamp Type"), format.String(aggregateAlert.QueryTimestampType)},
{format.String("Trigger Mode"), format.String(aggregateAlert.TriggerMode)},
{format.String("Run As User ID"), format.String(aggregateAlert.OwnershipRunAsID)},
Expand Down
4 changes: 2 additions & 2 deletions cmd/humioctl/alerts_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ func newAlertsShowCmd() *cobra.Command {
{format.String("Query Start"), format.String(alert.QueryStart)},
{format.String("Query String"), format.String(alert.QueryString)},
{format.String("Labels"), format.String(strings.Join(alert.Labels, ", "))},
{format.String("Throttle Time Millis"), format.Int(alert.ThrottleTimeMillis)},
{format.String("Throttle Time Millis"), format.Int64(alert.ThrottleTimeMillis)},
{format.String("Is Starred"), format.Bool(alert.IsStarred)},
{format.String("Last Error"), format.StringPtr(alert.LastError)},
{format.String("Throttle Field"), format.StringPtr(alert.ThrottleField)},
{format.String("Time Of Last Trigger"), format.IntPtr(alert.TimeOfLastTrigger)},
{format.String("Time Of Last Trigger"), format.Int64Ptr(alert.TimeOfLastTrigger)},
{format.String("Run As User ID"), format.String(alert.RunAsUserID)},
{format.String("Query Ownership Type"), format.String(alert.QueryOwnershipType)},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/humioctl/cluster_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func newClusterNodesCmd() *cobra.Command {

func printClusterNodeDetailsTable(cmd *cobra.Command, node api.ClusterNode) {
details := [][]format.Value{
{format.String("ID"), format.Int(node.Id)},
{format.String("ID"), format.Int64(node.Id)},
{format.String("Name"), format.String(node.Name)},
{format.String("URI"), format.String(node.Uri)},
{format.String("UUID"), format.String(node.Uuid)},
Expand Down
2 changes: 1 addition & 1 deletion cmd/humioctl/cluster_nodes_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func newClusterNodesListCmd() *cobra.Command {
rows := make([][]format.Value, len(nodes))
for i, node := range nodes {
rows[i] = []format.Value{
format.Int(node.Id),
format.Int64(node.Id),
format.String(node.Name),
format.Bool(node.CanBeSafelyUnregistered),
format.StringPtr(node.Zone),
Expand Down
2 changes: 1 addition & 1 deletion cmd/humioctl/filter_alerts_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func newFilterAlertsListCmd() *cobra.Command {
format.StringPtr(filterAlert.Description),
format.String(strings.Join(filterAlert.ActionNames, ", ")),
format.String(strings.Join(filterAlert.Labels, ", ")),
format.IntPtr(filterAlert.ThrottleTimeSeconds),
format.Int64Ptr(filterAlert.ThrottleTimeSeconds),
Comment thread
fjerlov-cs marked this conversation as resolved.
format.StringPtr(filterAlert.ThrottleField),
format.String(filterAlert.OwnershipRunAsID),
format.String(filterAlert.QueryOwnershipType),
Expand Down
2 changes: 1 addition & 1 deletion cmd/humioctl/filter_alerts_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func newFilterAlertsShowCmd() *cobra.Command {
{format.String("Query String"), format.String(filterAlert.QueryString)},
{format.String("Labels"), format.String(strings.Join(filterAlert.Labels, ", "))},
{format.String("Actions"), format.String(strings.Join(filterAlert.ActionNames, ", "))},
{format.String("Throttle Time Seconds"), format.IntPtr(filterAlert.ThrottleTimeSeconds)},
{format.String("Throttle Time Seconds"), format.Int64Ptr(filterAlert.ThrottleTimeSeconds)},
Comment thread
fjerlov-cs marked this conversation as resolved.
{format.String("Throttle Field"), format.StringPtr(filterAlert.ThrottleField)},
{format.String("Run As User ID"), format.String(filterAlert.OwnershipRunAsID)},
{format.String("Query Ownership Type"), format.String(filterAlert.QueryOwnershipType)},
Expand Down
2 changes: 1 addition & 1 deletion cmd/humioctl/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func printLicenseDetailsTable(cmd *cobra.Command, license api.License) {
details = append(details, []format.Value{format.String("License ID"), format.String(onprem.ID)})
details = append(details, []format.Value{format.String("Issued To"), format.String(onprem.IssuedTo)})
if onprem.NumberOfSeats != nil {
details = append(details, []format.Value{format.String("Number Of Seats"), format.Int(*onprem.NumberOfSeats)})
details = append(details, []format.Value{format.String("Number Of Seats"), format.Int64(*onprem.NumberOfSeats)})
}
}

Expand Down
1 change: 1 addition & 0 deletions cmd/humioctl/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ Common Management Commands:
rootCmd.AddCommand(newAlertsCmd())
rootCmd.AddCommand(newFilterAlertsCmd())
rootCmd.AddCommand(newScheduledSearchesCmd())
rootCmd.AddCommand(newScheduledSearchesV2Cmd())
rootCmd.AddCommand(newAggregateAlertsCmd())
rootCmd.AddCommand(newPackagesCmd())
rootCmd.AddCommand(newGroupsCmd())
Expand Down
2 changes: 1 addition & 1 deletion cmd/humioctl/scheduled_searches_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The install command allows you to install scheduled searches from a URL or from

cmd.Flags().StringVar(&filePath, "file", "", "The local file path to the scheduled search to install.")
cmd.Flags().StringVar(&url, "url", "", "A URL to fetch the scheduled search file from.")
cmd.Flags().StringVarP(&name, "name", "n", "", "Install the alert under a specific name, ignoring the `name` attribute in the alert file.")
cmd.Flags().StringVarP(&name, "name", "n", "", "Install the scheduled search under a specific name, ignoring the `name` attribute in the scheduled search file.")
cmd.MarkFlagsMutuallyExclusive("file", "url")
return &cmd
}
2 changes: 1 addition & 1 deletion cmd/humioctl/scheduled_searches_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func newScheduledSearchesListCmd() *cobra.Command {
format.String(scheduledSearch.QueryEnd),
format.String(scheduledSearch.TimeZone),
format.String(scheduledSearch.Schedule),
format.Int(scheduledSearch.BackfillLimit),
format.Int64(scheduledSearch.BackfillLimit),
format.String(strings.Join(scheduledSearch.ActionNames, ", ")),
format.String(strings.Join(scheduledSearch.Labels, ", ")),
format.Bool(scheduledSearch.Enabled),
Expand Down
2 changes: 1 addition & 1 deletion cmd/humioctl/scheduled_searches_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func newScheduledSearchesShowCmd() *cobra.Command {
{format.String("Query End"), format.String(scheduledSearch.QueryEnd)},
{format.String("Time Zone"), format.String(scheduledSearch.TimeZone)},
{format.String("Schedule"), format.String(scheduledSearch.Schedule)},
{format.String("Backfill Limit"), format.Int(scheduledSearch.BackfillLimit)},
{format.String("Backfill Limit"), format.Int64(scheduledSearch.BackfillLimit)},
{format.String("Enabled"), format.Bool(scheduledSearch.Enabled)},
{format.String("Actions"), format.String(strings.Join(scheduledSearch.ActionNames, ", "))},
{format.String("Run As User ID"), format.String(scheduledSearch.OwnershipRunAsID)},
Expand Down
35 changes: 35 additions & 0 deletions cmd/humioctl/scheduled_searches_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright © 2025 CrowdStrike
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"github.com/spf13/cobra"
)

func newScheduledSearchesV2Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "scheduled-searches-v2",
Short: "Manage scheduled searches",
}

cmd.AddCommand(newScheduledSearchesV2ListCmd())
cmd.AddCommand(newScheduledSearchesV2InstallCmd())
cmd.AddCommand(newScheduledSearchesV2ExportCmd())
cmd.AddCommand(newScheduledSearchesV2ExportAllCmd())
cmd.AddCommand(newScheduledSearchesV2RemoveCmd())
cmd.AddCommand(newScheduledSearchesV2ShowCmd())

return cmd
}
106 changes: 106 additions & 0 deletions cmd/humioctl/scheduled_searches_v2_export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright © 2025 CrowdStrike
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"os"

"github.com/humio/cli/internal/api"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)

func newScheduledSearchesV2ExportCmd() *cobra.Command {
var outputName string

cmd := cobra.Command{
Use: "export [flags] <view> <scheduled-search>",
Short: "Export a scheduled search <scheduled-search> in <view> to a file.",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
view := args[0]
scheduledSearchName := args[1]
client := NewApiClient(cmd)

scheduledSearches, err := client.ScheduledSearchesV2().List(view)
exitOnError(cmd, err, "Could not list scheduled searches")

var scheduledSearch api.ScheduledSearchV2
for _, ss := range scheduledSearches {
if ss.Name == scheduledSearchName {
scheduledSearch = ss
}
}

if scheduledSearch.ID == "" {
exitOnError(cmd, api.ScheduledSearchNotFound(scheduledSearchName), "Could not find scheduled search")
}

yamlData, err := yaml.Marshal(&scheduledSearch)
exitOnError(cmd, err, "Failed to serialize the scheduled search")

if outputName == "" {
outputName = sanitizeTriggerName(scheduledSearch.Name)
}

outFilePath := outputName + ".yaml"
err = os.WriteFile(outFilePath, yamlData, 0600)
exitOnError(cmd, err, "Error saving the scheduled search file")
},
}

cmd.Flags().StringVarP(&outputName, "output", "o", "", "The file path where the scheduled search should be written. Defaults to ./<scheduled-search-name>.yaml")

return &cmd
}

func newScheduledSearchesV2ExportAllCmd() *cobra.Command {
var outputDirectory string

cmd := cobra.Command{
Use: "export-all <view>",
Short: "Export all scheduled searches",
Long: `Export all scheduled searches to yaml files with naming <sanitized-scheduled-search-name>.yaml.`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
view := args[0]
client := NewApiClient(cmd)

var scheduledSearches []api.ScheduledSearchV2
scheduledSearches, err := client.ScheduledSearchesV2().List(view)
exitOnError(cmd, err, "Error fetching scheduled searches")

for i := range scheduledSearches {
yamlData, err := yaml.Marshal(&scheduledSearches[i])
exitOnError(cmd, err, "Failed to serialize the scheduled search")
scheduledSearchFilename := sanitizeTriggerName(scheduledSearches[i].Name) + ".yaml"

var outFilePath string
if outputDirectory != "" {
outFilePath = outputDirectory + "/" + scheduledSearchFilename
} else {
outFilePath = scheduledSearchFilename
}

err = os.WriteFile(outFilePath, yamlData, 0600)
exitOnError(cmd, err, "Error saving the scheduled search to file")
}
},
}

cmd.Flags().StringVarP(&outputDirectory, "outputDirectory", "d", "", "The file path where the scheduled searches should be written. Defaults to current directory.")

return &cmd
}
111 changes: 111 additions & 0 deletions cmd/humioctl/scheduled_searches_v2_install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright © 2025 CrowdStrike
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"fmt"
"os"

"github.com/humio/cli/internal/api"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)

func newScheduledSearchesV2InstallCmd() *cobra.Command {
var filePath, url, name string

cmd := cobra.Command{
Use: "install [flags] <view>",
Short: "Installs a scheduled search in a view",
Long: `Install a scheduled search from a URL or from a local file.

The install command allows you to install scheduled searches from a URL or from a local file, e.g.

$ humioctl scheduled-searches-v2 install viewName --url=https://example.com/acme/scheduled-search-v2.yaml

$ humioctl scheduled-searches-v2 install viewName --file=./scheduled-searches-v2.yaml

$ humioctl scheduled-searches-v2 install viewName --file=./scheduled-search-v1.yaml
This will install the legacy scheduled search with the CreateScheduledSearch mutation (deprecated for removal in 1.231).
`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
var content []byte
var err error

// Check that we got the right number of argument
// if we only got <view> you must supply --file or --url.
if l := len(args); l == 1 {
if filePath != "" {
content, err = getBytesFromFile(filePath)
} else if url != "" {
content, err = getBytesFromURL(url)
} else {
cmd.Printf("You must specify a path using --file or --url\n")
os.Exit(1)
}
}
exitOnError(cmd, err, "Could to load the scheduled search")

client := NewApiClient(cmd)
viewName := args[0]

var scheduledSearchV2 api.ScheduledSearchV2
scheduledSearchV2, parseErr := tryParseScheduledSearchV2(content)
if parseErr != nil {
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Yaml file could be parsed as scheduled search v2, err=%s. Attempting to parse as scheduled search v1 and create using deprecated CreateScheduledSearch mutation.\n", parseErr)
var scheduledSearchV1 api.ScheduledSearch
err = yaml.Unmarshal(content, &scheduledSearchV1)

exitOnError(cmd, err, "Could not unmarshal the scheduled search as a scheduled search v1.")

if name != "" {
scheduledSearchV2.Name = name
}

_, err = client.ScheduledSearchesV2().Create(viewName, &scheduledSearchV2)
exitOnError(cmd, err, "Could not create the scheduled search using deprecated CreateScheduledSearch mutation.")

_, _ = fmt.Fprintln(cmd.OutOrStdout(), "Scheduled search v1 created using deprecated CreateScheduledSearch mutation.")
} else {
if name != "" {
scheduledSearchV2.Name = name
}

_, err = client.ScheduledSearchesV2().Create(viewName, &scheduledSearchV2)
exitOnError(cmd, err, "Could not create the scheduled search")

_, _ = fmt.Fprintln(cmd.OutOrStdout(), "Scheduled search created")
os.Exit(1)
}
},
}

cmd.Flags().StringVar(&filePath, "file", "", "The local file path to the scheduled search to install.")
cmd.Flags().StringVar(&url, "url", "", "A URL to fetch the scheduled search file from.")
cmd.Flags().StringVarP(&name, "name", "n", "", "Install the scheduled search under a specific name, ignoring the `name` attribute in the scheduled search file.")
cmd.MarkFlagsMutuallyExclusive("file", "url")
return &cmd
}

func tryParseScheduledSearchV2(content []byte) (api.ScheduledSearchV2, error) {
var scheduledSearchV2 api.ScheduledSearchV2
err := yaml.Unmarshal(content, &scheduledSearchV2)
if err != nil {
return api.ScheduledSearchV2{}, err
} else {
return scheduledSearchV2, nil
}
}
Loading