5151
5252CHRONICLE_API_BASE_URL = "https://chronicle.googleapis.com"
5353SCOPES = [
54- "https://www.googleapis.com/auth/cloud-platform" ,
54+ "https://www.googleapis.com/auth/cloud-platform" ,
5555]
5656
5757
@@ -61,7 +61,7 @@ def batch_update_curated_rule_set_deployments(
6161 proj_instance : str ,
6262 proj_region : str ,
6363) -> Mapping [str , Any ]:
64- """Batch updates multiple curated rule set deployments.
64+ """Batch updates multiple curated rule set deployments.
6565
6666 Args:
6767 http_session: Authorized session for HTTP requests.
@@ -79,94 +79,96 @@ def batch_update_curated_rule_set_deployments(
7979 Requires the following IAM permission on the parent resource:
8080 chronicle.curatedRuleSetDeployments.update
8181 """
82- base_url_with_region = regions .url_always_prepend_region (
83- CHRONICLE_API_BASE_URL ,
84- proj_region
85- )
86- parent = f"projects/{ proj_id } /locations/{ proj_region } /instances/{ proj_instance } "
87-
88- # We use "-" in the URL because we provide category and rule_set IDs
89- # in the request data
90- url = f"{ base_url_with_region } /v1alpha/{ parent } /curatedRuleSetCategories/-/curatedRuleSets/-/curatedRuleSetDeployments:batchUpdate"
91-
92- def make_deployment_name (category : str , rule_set : str , precision : str ) -> str :
93- """Helper function to create a deployment name."""
94- return f"{ parent } /curatedRuleSetCategories/{ category } /curatedRuleSets/{ rule_set } /curatedRuleSetDeployments/{ precision } "
95-
96- # Example deployment configurations - update these with actual IDs
97- # Deployment A
98- category_a = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
99- rule_set_a = "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"
100- precision_a = "broad"
101-
102- # Deployment B
103- category_b = "cccccccc-cccc-cccc-cccc-cccccccccccc"
104- rule_set_b = "dddddddd-dddd-dddd-dddd-dddddddddddd"
105- precision_b = "precise"
106-
107- print ("\n NOTE: Using example category/rule_set/precision IDs." )
108- print ("Please update the script with actual IDs before use.\n " )
109-
110- json_data = {
111- "parent" : f"{ parent } /curatedRuleSetCategories/-/curatedRuleSets/-" ,
112- "requests" : [
113- {
114- "curated_rule_set_deployment" : {
115- "name" : make_deployment_name (
116- category_a ,
117- rule_set_a ,
118- precision_a ,
119- ),
120- "enabled" : True ,
121- "alerting" : False ,
122- },
123- "update_mask" : {
124- "paths" : ["alerting" , "enabled" ],
125- },
126- },
127- {
128- "curated_rule_set_deployment" : {
129- "name" : make_deployment_name (
130- category_b ,
131- rule_set_b ,
132- precision_b ,
133- ),
134- "enabled" : True ,
135- "alerting" : True ,
136- },
137- "update_mask" : {
138- "paths" : ["alerting" , "enabled" ],
139- },
140- },
141- ],
142- }
143-
144- response = http_session .request ("POST" , url , json = json_data )
145- if response .status_code >= 400 :
146- print (response .text )
147- response .raise_for_status ()
148-
149- return response .json ()
82+ base_url_with_region = regions .url_always_prepend_region (
83+ CHRONICLE_API_BASE_URL , proj_region )
84+ parent = f"projects/{ proj_id } /locations/{ proj_region } /instances/{ proj_instance } "
85+
86+ # We use "-" in the URL because we provide category and rule_set IDs
87+ # in the request data
88+ url = f"{ base_url_with_region } /v1alpha/{ parent } /curatedRuleSetCategories/-/curatedRuleSets/-/curatedRuleSetDeployments:batchUpdate"
89+
90+ def make_deployment_name (category : str , rule_set : str ,
91+ precision : str ) -> str :
92+ """Helper function to create a deployment name."""
93+ return f"{ parent } /curatedRuleSetCategories/{ category } /curatedRuleSets/{ rule_set } /curatedRuleSetDeployments/{ precision } "
94+
95+ # Example deployment configurations - update these with actual IDs
96+ # Deployment A
97+ category_a = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
98+ rule_set_a = "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"
99+ precision_a = "broad"
100+
101+ # Deployment B
102+ category_b = "cccccccc-cccc-cccc-cccc-cccccccccccc"
103+ rule_set_b = "dddddddd-dddd-dddd-dddd-dddddddddddd"
104+ precision_b = "precise"
105+
106+ print ("\n NOTE: Using example category/rule_set/precision IDs." )
107+ print ("Please update the script with actual IDs before use.\n " )
108+
109+ json_data = {
110+ "parent" :
111+ f"{ parent } /curatedRuleSetCategories/-/curatedRuleSets/-" ,
112+ "requests" : [
113+ {
114+ "curated_rule_set_deployment" : {
115+ "name" :
116+ make_deployment_name (
117+ category_a ,
118+ rule_set_a ,
119+ precision_a ,
120+ ),
121+ "enabled" :
122+ True ,
123+ "alerting" :
124+ False ,
125+ },
126+ "update_mask" : {
127+ "paths" : ["alerting" , "enabled" ],
128+ },
129+ },
130+ {
131+ "curated_rule_set_deployment" : {
132+ "name" :
133+ make_deployment_name (
134+ category_b ,
135+ rule_set_b ,
136+ precision_b ,
137+ ),
138+ "enabled" :
139+ True ,
140+ "alerting" :
141+ True ,
142+ },
143+ "update_mask" : {
144+ "paths" : ["alerting" , "enabled" ],
145+ },
146+ },
147+ ],
148+ }
149+
150+ response = http_session .request ("POST" , url , json = json_data )
151+ if response .status_code >= 400 :
152+ print (response .text )
153+ response .raise_for_status ()
154+
155+ return response .json ()
150156
151157
152158if __name__ == "__main__" :
153- parser = argparse .ArgumentParser ()
154- # common
155- chronicle_auth .add_argument_credentials_file (parser )
156- project_id .add_argument_project_id (parser )
157- project_instance .add_argument_project_instance (parser )
158- regions .add_argument_region (parser )
159-
160- args = parser .parse_args ()
161-
162- auth_session = chronicle_auth .initialize_http_session (
163- args .credentials_file ,
164- SCOPES
165- )
166- result = batch_update_curated_rule_set_deployments (
167- auth_session ,
168- args .project_id ,
169- args .project_instance ,
170- args .region
171- )
172- print (json .dumps (result , indent = 2 ))
159+ parser = argparse .ArgumentParser ()
160+ # common
161+ chronicle_auth .add_argument_credentials_file (parser )
162+ project_id .add_argument_project_id (parser )
163+ project_instance .add_argument_project_instance (parser )
164+ regions .add_argument_region (parser )
165+
166+ args = parser .parse_args ()
167+
168+ auth_session = chronicle_auth .initialize_http_session (
169+ args .credentials_file , SCOPES )
170+ result = batch_update_curated_rule_set_deployments (auth_session ,
171+ args .project_id ,
172+ args .project_instance ,
173+ args .region )
174+ print (json .dumps (result , indent = 2 ))
0 commit comments