Skip to content
This repository was archived by the owner on Dec 31, 2023. It is now read-only.

Commit 85a1420

Browse files
Merge branch 'snippets-v3-samples' into add-snippets-v3-samples
2 parents c51abed + 45d508e commit 85a1420

33 files changed

+2734
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
backup.json
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
.. This file is automatically generated. Do not edit this file directly.
2+
3+
Google Stackdriver Alerting API Python Samples
4+
===============================================================================
5+
6+
.. image:: https://gstatic.com/cloudssh/images/open-btn.png
7+
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=monitoring/api/v3/alerts-client/README.rst
8+
9+
10+
This directory contains samples for Google Stackdriver Alerting API. Stackdriver Monitoring collects metrics, events, and metadata from Google Cloud Platform, Amazon Web Services (AWS), hosted uptime probes, application instrumentation, and a variety of common application components including Cassandra, Nginx, Apache Web Server, Elasticsearch and many others. Stackdriver's Alerting API allows you to create, delete, and make back up copies of your alert policies.
11+
12+
13+
14+
15+
.. _Google Stackdriver Alerting API: https://cloud.google.com/monitoring/alerts/
16+
17+
To run the sample, you need to enable the API at: https://console.cloud.google.com/apis/library/monitoring.googleapis.com
18+
19+
To run the sample, you need to have `Monitoring Admin` role.
20+
21+
Please visit [the Cloud Console UI of this API](https://console.cloud.google.com/monitoring) and [create a new Workspace with the same name of your Cloud project](https://cloud.google.com/monitoring/workspaces/create).
22+
23+
24+
Setup
25+
-------------------------------------------------------------------------------
26+
27+
28+
Authentication
29+
++++++++++++++
30+
31+
This sample requires you to have authentication setup. Refer to the
32+
`Authentication Getting Started Guide`_ for instructions on setting up
33+
credentials for applications.
34+
35+
.. _Authentication Getting Started Guide:
36+
https://cloud.google.com/docs/authentication/getting-started
37+
38+
Install Dependencies
39+
++++++++++++++++++++
40+
41+
#. Clone python-docs-samples and change directory to the sample directory you want to use.
42+
43+
.. code-block:: bash
44+
45+
$ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
46+
47+
#. Install `pip`_ and `virtualenv`_ if you do not already have them. You may want to refer to the `Python Development Environment Setup Guide`_ for Google Cloud Platform for instructions.
48+
49+
.. _Python Development Environment Setup Guide:
50+
https://cloud.google.com/python/setup
51+
52+
#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.
53+
54+
.. code-block:: bash
55+
56+
$ virtualenv env
57+
$ source env/bin/activate
58+
59+
#. Install the dependencies needed to run the samples.
60+
61+
.. code-block:: bash
62+
63+
$ pip install -r requirements.txt
64+
65+
.. _pip: https://pip.pypa.io/
66+
.. _virtualenv: https://virtualenv.pypa.io/
67+
68+
Samples
69+
-------------------------------------------------------------------------------
70+
71+
Snippets
72+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
73+
74+
.. image:: https://gstatic.com/cloudssh/images/open-btn.png
75+
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=monitoring/api/v3/alerts-client/snippets.py,monitoring/api/v3/alerts-client/README.rst
76+
77+
78+
79+
80+
To run this sample:
81+
82+
.. code-block:: bash
83+
84+
$ python snippets.py
85+
86+
usage: snippets.py [-h]
87+
{list-alert-policies,list-notification-channels,enable-alert-policies,disable-alert-policies,replace-notification-channels,backup,restore}
88+
...
89+
90+
Demonstrates AlertPolicy API operations.
91+
92+
positional arguments:
93+
{list-alert-policies,list-notification-channels,enable-alert-policies,disable-alert-policies,replace-notification-channels,backup,restore}
94+
list-alert-policies
95+
list-notification-channels
96+
enable-alert-policies
97+
Enable or disable alert policies in a project.
98+
Arguments: project_name (str) enable (bool): Enable or
99+
disable the policies. filter_ (str, optional): Only
100+
enable/disable alert policies that match this filter_.
101+
See
102+
https://cloud.google.com/monitoring/api/v3/sorting-
103+
and-filtering
104+
disable-alert-policies
105+
Enable or disable alert policies in a project.
106+
Arguments: project_name (str) enable (bool): Enable or
107+
disable the policies. filter_ (str, optional): Only
108+
enable/disable alert policies that match this filter_.
109+
See
110+
https://cloud.google.com/monitoring/api/v3/sorting-
111+
and-filtering
112+
replace-notification-channels
113+
backup
114+
restore
115+
116+
optional arguments:
117+
-h, --help show this help message and exit
118+
119+
120+
121+
122+
123+
The client library
124+
-------------------------------------------------------------------------------
125+
126+
This sample uses the `Google Cloud Client Library for Python`_.
127+
You can read the documentation for more details on API usage and use GitHub
128+
to `browse the source`_ and `report issues`_.
129+
130+
.. _Google Cloud Client Library for Python:
131+
https://googlecloudplatform.github.io/google-cloud-python/
132+
.. _browse the source:
133+
https://github.com/GoogleCloudPlatform/google-cloud-python
134+
.. _report issues:
135+
https://github.com/GoogleCloudPlatform/google-cloud-python/issues
136+
137+
138+
.. _Google Cloud SDK: https://cloud.google.com/sdk/
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This file is used to generate README.rst
2+
3+
product:
4+
name: Google Stackdriver Alerting API
5+
short_name: Stackdriver Alerting API
6+
url: https://cloud.google.com/monitoring/alerts/
7+
description: >
8+
Stackdriver Monitoring collects metrics, events, and metadata from Google
9+
Cloud Platform, Amazon Web Services (AWS), hosted uptime probes,
10+
application instrumentation, and a variety of common application
11+
components including Cassandra, Nginx, Apache Web Server, Elasticsearch
12+
and many others. Stackdriver's Alerting API allows you to create,
13+
delete, and make back up copies of your alert policies.
14+
15+
required_api_url: https://console.cloud.google.com/apis/library/monitoring.googleapis.com
16+
required_role: Monitoring Admin
17+
other_required_steps: >
18+
Please visit [the Cloud Console UI of this
19+
API](https://console.cloud.google.com/monitoring) and create a new
20+
Workspace with the same name of your Cloud project.
21+
22+
setup:
23+
- auth
24+
- install_deps
25+
26+
samples:
27+
- name: Snippets
28+
file: snippets.py
29+
show_help: true
30+
31+
cloud_client_library: true
32+
33+
folder: monitoring/api/v3/alerts-client
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Default TEST_CONFIG_OVERRIDE for python repos.
16+
17+
# You can copy this file into your directory, then it will be inported from
18+
# the noxfile.py.
19+
20+
# The source of truth:
21+
# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py
22+
23+
TEST_CONFIG_OVERRIDE = {
24+
# You can opt out from the test for specific Python versions.
25+
'ignored_versions': ["2.7"],
26+
27+
# Declare optional test sessions you want to opt-in. Currently we
28+
# have the following optional test sessions:
29+
# 'cloud_run' # Test session for Cloud Run application.
30+
'opt_in_sessions': [],
31+
32+
# An envvar key for determining the project id to use. Change it
33+
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
34+
# build specific Cloud project. You can also use your own string
35+
# to use your own Cloud project.
36+
# 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT',
37+
'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
38+
39+
# A dictionary you want to inject into your test. Don't put any
40+
# secrets here. These values will override predefined values.
41+
'envs': {},
42+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pytest==6.0.1
2+
retrying==1.3.3
3+
flaky==3.7.0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
google-cloud-monitoring==1.1.0
2+
tabulate==0.8.7

0 commit comments

Comments
 (0)