-
Notifications
You must be signed in to change notification settings - Fork 237
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
teams and services analytics endpoints #312
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
"github.com/PagerDuty/go-pagerduty" | ||
"github.com/mitchellh/cli" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type AnalyticsServiceShow struct { | ||
Meta | ||
} | ||
|
||
func AnalyticsGetAggregatedServiceDataCommand() (cli.Command, error) { | ||
return &AnalyticsServiceShow{}, nil | ||
} | ||
|
||
func (c *AnalyticsServiceShow) Help() string { | ||
helpText := ` | ||
analytics service show | ||
Options: | ||
-(service_id|team_id) #MANDATORY provide service or team id to stats on. | ||
-start #Optional RFC3339 format default : 7 days ago | ||
-end #Optional RFC3339 format default : now | ||
-urgency #Optional (high|low) | ||
` + c.Meta.Help() | ||
return strings.TrimSpace(helpText) | ||
} | ||
|
||
func (c *AnalyticsServiceShow) Synopsis() string { | ||
return "Get aggregated service data analytics" | ||
} | ||
|
||
func (c *AnalyticsServiceShow) Run(args []string) int { | ||
flags := c.Meta.FlagSet("analytics service show") | ||
flags.Usage = func() { fmt.Println(c.Help()) } | ||
servID := flags.String("service_id", "", "Service ID") | ||
now := time.Now() | ||
sevenDaysAgo := now.Add(time.Duration(-24*7) * time.Hour) | ||
start := flags.String("start", sevenDaysAgo.Format(time.RFC3339), "start date") | ||
end := flags.String("end", now.Format(time.RFC3339), "end date") | ||
urgency := flags.String("urgency", "", "high|low") | ||
teamID := flags.String("team_id", "", "team ID") | ||
|
||
//log.SetLevel(log.DebugLevel) | ||
if err := flags.Parse(args); err != nil { | ||
log.Errorln(err) | ||
return -1 | ||
} | ||
|
||
if err := c.Meta.Setup(); err != nil { | ||
log.Error(err) | ||
return -1 | ||
} | ||
|
||
client := c.Meta.Client() | ||
|
||
serviceIds := make([]string, 1) | ||
if *servID == "" { | ||
serviceIds = nil | ||
} else { | ||
serviceIds[0] = *servID | ||
} | ||
|
||
teamIds := make([]string, 1) | ||
if *teamID == "" { | ||
teamIds = nil | ||
} else { | ||
teamIds[0] = *teamID | ||
} | ||
|
||
analyticsFilter := pagerduty.AnalyticsFilter{ | ||
CreatedAtStart: *start, | ||
CreatedAtEnd: *end, | ||
Urgency: *urgency, | ||
ServiceIDs: serviceIds, | ||
TeamIDs: teamIds, | ||
} | ||
|
||
analytics := pagerduty.AnalyticsRequest{ | ||
AnalyticsFilter: &analyticsFilter, | ||
AggregateUnit: "day", | ||
TimeZone: "Etc/UTC", | ||
} | ||
|
||
aggregatedServiceData, err := client.GetAggregatedServiceData(context.Background(), analytics) | ||
if err != nil { | ||
log.Error(err) | ||
return -1 | ||
} | ||
|
||
aggregatedServiceDataBytes, err := json.Marshal(aggregatedServiceData) | ||
if err != nil { | ||
log.Error(err) | ||
return -1 | ||
} | ||
fmt.Println(string(aggregatedServiceDataBytes)) | ||
return 0 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for asking this of you since this wasn't your change, but your PR made me look at things again and I am now realizing I missed this in the original PR. Would you rename this field in your PR to just be
Filters *AnalyticsFilter
. We've not released this yet, and so I'd rather we get this done right versus letting it bleed out once we do releasev1.4.0
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AnalyticsFilter
has been changed toFilters
👍There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you may have misread my comment, I'm sorry. Was only wanting the field name updated, not the type too. The type made sense because it's the filters for the Analytics stuff, but
AnalyticsResponse.AnalyticsFilters
stutters a little bit, whileAnalyticsResponse.Filters
is easier to communicate.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did misread your comment. Apologies 😅 I went ahead and changed that in the new commit. Please let me know if you see anything else 👍