Skip to content

Commit

Permalink
added networks
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyaven committed Aug 26, 2023
1 parent 931964a commit 083fa3d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
63 changes: 62 additions & 1 deletion notebooks/google/google_audit/3_network.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
" JSON_EXTRACT(routingConfig, '$.routingMode') as routingMode,\n",
" subnetworks\n",
" FROM google.compute.networks WHERE project = '{project}'\n",
" AND name IS NOT NULL\n",
" \"\"\"\n",
" for project in compute_enabled_projects\n",
"]\n",
"\n",
"networks_df = (lambda df: df[df['name'] != 'null'])(run_stackql_queries(queries))\n",
"networks_df = run_stackql_queries(queries)\n",
"networked_projects = list(networks_df['project'].unique())\n",
"networks_df"
]
},
Expand Down Expand Up @@ -78,6 +80,65 @@
"subnetworks_df = run_stackql_queries(queries)\n",
"subnetworks_df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"# get interconnects\n",
"queries = [\n",
" f\"\"\"\n",
" SELECT *\n",
" FROM google.compute.interconnects WHERE project = '{project}'\n",
" AND name IS NOT NULL\n",
" \"\"\"\n",
" for project in networked_projects\n",
"]\n",
"\n",
"interconnects_df = run_stackql_queries(queries, True)\n",
"interconnects_df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"# get vpns\n",
"queries = [\n",
" f\"\"\"\n",
" SELECT \n",
" name,\n",
" SPLIT_PART(network, '/', 9) as network,\n",
" SPLIT_PART(region, '/', 8) as region,\n",
" vpnInterfaces\n",
" FROM google.compute.vpn_gateways WHERE project = '{project}'\n",
" \"\"\"\n",
" for project in networked_projects\n",
"]\n",
"\n",
"vpns_df = run_stackql_queries(queries, True)\n",
"vpns_df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"# Convert the string to list of dictionaries and explode\n",
"exploded_df = vpns_df.assign(vpnInterfaces=vpns_df['vpnInterfaces'].apply(ast.literal_eval)).explode('vpnInterfaces')\n",
"exploded_df[['id', 'ipAddress']] = exploded_df['vpnInterfaces'].apply(pd.Series)\n",
"exploded_df.drop(columns=['vpnInterfaces'], inplace=True)\n",
"exploded_df"
]
}
],
"metadata": {
Expand Down
2 changes: 1 addition & 1 deletion notebooks/google/google_audit/includes/shared-setup.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"outputs": [],
"source": [
"## imports and object instantiation\n",
"import json, time, itertools, sys, threading, psycopg2, pickle\n",
"import json, time, itertools, sys, threading, psycopg2, pickle, ast\n",
"from concurrent.futures import ThreadPoolExecutor, as_completed\n",
"import ipywidgets as widgets\n",
"import pandas as pd\n",
Expand Down

0 comments on commit 083fa3d

Please sign in to comment.