Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Add table turbot_notification #9

Merged
merged 29 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Use SQL to query infrastructure including servers, networks, identity and more f

- **[Get started →](https://hub.steampipe.io/plugins/turbot/turbot)**
- Documentation: [Table definitions & examples](https://hub.steampipe.io/plugins/turbot/turbot/tables)
- Community: [Slack Channel](https://join.slack.com/t/steampipe/shared_invite/zt-oij778tv-lYyRTWOTMQYBVAbtPSWs3g)
- Community: [Slack Channel](https://steampipe.io/community/join)
- Get involved: [Issues](https://github.com/turbot/steampipe-plugin-turbot/issues)

## Quick start
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ connection "turbot" {
## Get involved

- Open source: https://github.com/turbot/steampipe-plugin-turbot
- Community: [Slack Channel](https://join.slack.com/t/steampipe/shared_invite/zt-oij778tv-lYyRTWOTMQYBVAbtPSWs3g)
- Community: [Slack Channel](https://steampipe.io/community/join)

## Advanced configuration options

Expand Down
163 changes: 163 additions & 0 deletions docs/tables/turbot_notification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# Table: turbot_notification

Notifications represent significant events in the lifecycle of turbot infrastructure, including:

- A history of change for a resource, e.g., my-s3-bucket.
- A log of state changes and actions performed by a control, e.g., the Tags control for my-s3-bucket.
- Changes to policy settings and policy values updated as a result.
- Records of permission grants, activations, deactivations and revocations.

When querying this table, we recommend using at least one of these columns (usually in the `where` clause):

- `id`
- `resource_id`
- `notification_type`
- `control_id`
- `control_type_id`
- `control_type_uri`
- `resource_type_id`
- `resource_type_uri`
- `policy_setting_type_id`
- `policy_setting_type_uri`
- `actor_identity_id`
- `create_timestamp`
- `filter`

For more information on how to construct a `filter`, please see [Notifications examples](https://turbot.com/v5/docs/reference/filter/notifications#examples).

## Examples

### Find all Turbot grants activations in last 1 week using `filter`

```sql
select
active_grant_id,
notification_type,
active_grant_type_title,
active_grant_level_title,
create_timestamp,
actor_identity_trunk_title,
active_grant_identity_trunk_title,
active_grant_valid_to_timestamp,
active_grant_identity_profile_id,
resource_title
from
turbot_notification
where
filter = 'notificationType:activeGrant createTimestamp:>T-1w'
and active_grant_type_title = 'Turbot'
order by
create_timestamp desc,
notification_type,
actor_identity_trunk_title,
resource_title;
```

### Find all AWS grants activations in last 7 days

```sql
select
active_grant_id,
notification_type,
active_grant_type_title,
active_grant_level_title,
create_timestamp,
actor_identity_trunk_title,
active_grant_identity_trunk_title,
active_grant_valid_to_timestamp,
active_grant_identity_profile_id,
resource_title
from
turbot_notification
where
notification_type = 'active_grants_created'
and create_timestamp >= (current_date - interval '7' day)
and active_grant_type_title = 'AWS'
order by
create_timestamp desc,
notification_type,
actor_identity_trunk_title,
resource_title;
```

### Find all AWS S3 buckets created notifications in last 7 days

```sql
select
create_timestamp,
resource_id,
resource_title,
resource_trunk_title,
actor_identity_trunk_title
from
turbot_notification
where
notification_type = 'resource_created'
and create_timestamp >= (current_date - interval '120' day)
and resource_type_uri = 'tmod:@turbot/aws-s3#/resource/types/bucket'
order by
create_timestamp desc;
```

### All policy settings notifications on a given resource or below in last 90 days

```sql
select
notification_type,
create_timestamp,
policy_setting_id,
policy_setting_type_trunk_title,
policy_setting_type_uri,
resource_trunk_title,
resource_type_trunk_title,
policy_setting_type_read_only,
policy_setting_type_secret,
policy_setting_value
from
turbot_notification
where
resource_id = 191382256916538
and create_timestamp >= (current_date - interval '90' day)
and filter = 'notificationType:policySetting level:self,descendant'
order by
create_timestamp desc;
```

### All policy settings notifications for AWS > Account > Regions policy

```sql
select
notification_type,
create_timestamp,
policy_setting_id,
resource_id,
resource_trunk_title,
jsonb_pretty(policy_setting_value::jsonb) as policy_setting_value
from
turbot_notification
where
policy_setting_type_uri = 'tmod:@turbot/aws#/policy/types/regionsDefault'
and filter = 'notificationType:policySetting level:self'
order by
create_timestamp desc;
```

### All notifications for AWS > Account > Budget > Budget control

```sql
select
notification_type,
create_timestamp,
control_id,
resource_trunk_title,
control_state,
control_reason
from
turbot_notification
where
control_type_uri = 'tmod:@turbot/aws#/control/types/budget'
and filter = 'notificationType:control level:self'
order by
resource_id,
create_timestamp desc;
```
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ require (
github.com/go-yaml/yaml v2.1.0+incompatible
github.com/hashicorp/terraform v0.12.0
github.com/machinebox/graphql v0.2.3-0.20180904014615-9835de6386a3
github.com/matryer/is v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/matryer/is v1.4.0 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.3.3
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0
github.com/turbot/go-kit v0.3.0
github.com/turbot/steampipe-plugin-sdk v1.8.2
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)

require (
Expand Down Expand Up @@ -45,6 +45,7 @@ require (
github.com/iancoleman/strcase v0.1.2 // indirect
github.com/keybase/go-crypto v0.0.0-20161004153544-93f5b35093ba // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.10 // indirect
github.com/mattn/go-runewidth v0.0.7 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
Expand All @@ -60,6 +61,5 @@ require (
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
google.golang.org/grpc v1.41.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v2 v2.2.3 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
)
11 changes: 5 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ github.com/machinebox/graphql v0.2.3-0.20180904014615-9835de6386a3/go.mod h1:F+k
github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho=
github.com/masterzen/simplexml v0.0.0-20160608183007-4572e39b1ab9/go.mod h1:kCEbxUJlNDEBNbdQMkPSp6yaKcRXVI6f4ddk8Riv4bc=
github.com/masterzen/winrm v0.0.0-20190223112901-5e5c9a7fe54b/go.mod h1:wr1VqkwW0AB5JS0QLy5GpVMS9E3VtRoSYXUYyVk46KY=
github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A=
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
Expand All @@ -250,9 +250,8 @@ github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
Expand Down Expand Up @@ -442,7 +441,6 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -522,8 +520,9 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o=
Expand Down
25 changes: 13 additions & 12 deletions helpers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package helpers

import (
"encoding/json"
"github.com/stretchr/testify/assert"
"log"
"testing"

"github.com/stretchr/testify/assert"
)

func TestRemoveProperties(t *testing.T) {
Expand All @@ -15,43 +16,43 @@ func TestRemoveProperties(t *testing.T) {
expected []interface{}
}
tests := []test{
test{
{
"No exclusions",
[]interface{}{"a", "b", "c"},
[]string{},
[]interface{}{"a", "b", "c"},
},
test{
{
"String exclusions",
[]interface{}{"a", "b", "c"},
[]string{"a"},
[]interface{}{"b", "c"},
},
test{
{
"All excluded",
[]interface{}{"a", "b", "c"},
[]string{"a", "b", "c"},
[]interface{}(nil),
},
test{
{
"Map exclusion",
[]interface{}{"a", "b", map[string]string{"c": "C", "d": "D"}},
[]string{"c"},
[]interface{}{"a", "b", map[string]string{"d": "D"}},
},
test{
{
"2 map exclusions",
[]interface{}{"a", "b", map[string]string{"c": "C", "d": "D"}, map[string]string{"e": "E", "f": "F"}},
[]string{"c", "f"},
[]interface{}{"a", "b", map[string]string{"d": "D"}, map[string]string{"e": "E"}},
},
test{
{
"No matching exclusions",
[]interface{}{"a", "b", "c"},
[]string{"d"},
[]interface{}{"a", "b", "c"},
},
test{
{
"No matching exclusions with map",
[]interface{}{"a", "b", map[string]string{"c": "C", "d": "D"}},
[]string{"e"},
Expand All @@ -72,14 +73,14 @@ func TestGetNullProperties(t *testing.T) {
expected []interface{}
}
tests := []test{
test{
{
"Empty object",
`{
"allOf": []
}`,
[]interface{}{nil},
},
test{
{
"Single exclusion",
`{
"allOf": [
Expand All @@ -104,7 +105,7 @@ func TestGetNullProperties(t *testing.T) {
}`,
[]interface{}{"Id"},
},
test{
{
"No exclusion",
`{
"allOf": [
Expand All @@ -121,7 +122,7 @@ func TestGetNullProperties(t *testing.T) {
}`,
[]interface{}(nil),
},
test{
{
"Multiple exclusion",
`{
"allOf": [
Expand Down
1 change: 1 addition & 0 deletions turbot/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
TableMap: map[string]*plugin.Table{
"turbot_control": tableTurbotControl(ctx),
"turbot_control_type": tableTurbotControlType(ctx),
"turbot_notification": tableTurbotNotification(ctx),
"turbot_policy_setting": tableTurbotPolicySetting(ctx),
"turbot_policy_type": tableTurbotPolicyType(ctx),
"turbot_resource": tableTurbotResource(ctx),
Expand Down
Loading