Skip to content

Commit c5efc3b

Browse files
authored
Creating sample for StackDriver Alerts. (GoogleCloudPlatform#1063)
1 parent e8aff30 commit c5efc3b

File tree

5 files changed

+601
-0
lines changed

5 files changed

+601
-0
lines changed

monitoring/v3/README.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Cloud Monitoring Sample
2+
3+
Simple command-line program to demonstrate connecting to the Google
4+
Monitoring API to retrieve and modify Alerts data.
5+
6+
## Prerequisites to run locally:
7+
8+
* [Maven 3](https://maven.apache.org)
9+
* [GCloud CLI](https://cloud.google.com/sdk/gcloud/)
10+
* Create a Cloud project
11+
12+
# Set Up Your Local Dev Environment
13+
14+
Create local credentials by running the following command and following the oauth2 flow:
15+
16+
gcloud beta auth application-default login
17+
18+
To run:
19+
20+
* `mvn clean install`
21+
* `./manage_alerts_sample.sh <YOUR-PROJECT-ID> <command> <args>
22+
23+
## Running on GCE, GAE, or other environments
24+
25+
On Google App Engine, the credentials should be found automatically.
26+
27+
On Google Compute Engine, the credentials should be found automatically, but require that
28+
you create the instance with the correct scopes.
29+
30+
gcloud compute instances create --scopes="https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/compute,https://www.googleapis.com/auth/compute.readonly" test-instance
31+
32+
If you did not create the instance with the right scopes, you can still upload a JSON service
33+
account and set `GOOGLE_APPLICATION_CREDENTIALS` as described below.
34+
35+
## Using a Service Account
36+
37+
In non-Google Cloud environments, GCE instances created without the correct scopes, or local
38+
workstations if the `gcloud beta auth application-default login` command fails, use a Service
39+
Account by doing the following:
40+
41+
* Go to API Manager -> Credentials
42+
* Click 'New Credentials', and create a Service Account or [click here](https://console.cloud.google
43+
.com/project/_/apiui/credential/serviceaccount)
44+
Download the JSON for this service account, and set the `GOOGLE_APPLICATION_CREDENTIALS`
45+
environment variable to point to the file containing the JSON credentials.
46+
47+
48+
export GOOGLE_APPLICATION_CREDENTIALS=~/Downloads/<project-id>-0123456789abcdef.json

monitoring/v3/manage_alerts_sample.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env bash
2+
mvn exec:java -Dexec.mainClass=AlertSample -Dexec.args="$1"

monitoring/v3/pom.xml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!--
2+
Copyright 2018 Google Inc. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<project>
17+
<modelVersion>4.0.0</modelVersion>
18+
<groupId>com.example.monitoring</groupId>
19+
<artifactId>monitoring-google-cloud-v3-samples</artifactId>
20+
<version>0.1-SNAPSHOT</version>
21+
<packaging>jar</packaging>
22+
23+
<!--
24+
The parent pom defines common style checks and testing strategies for our samples.
25+
Removing or replacing it should not affect the execution of the samples in anyway.
26+
-->
27+
<parent>
28+
<groupId>com.google.cloud.samples</groupId>
29+
<artifactId>shared-configuration</artifactId>
30+
<version>1.0.8</version>
31+
</parent>
32+
33+
<properties>
34+
<maven.compiler.target>1.8</maven.compiler.target>
35+
<maven.compiler.source>1.8</maven.compiler.source>
36+
</properties>
37+
38+
<dependencies>
39+
<dependency>
40+
<groupId>com.google.cloud</groupId>
41+
<artifactId>google-cloud-monitoring</artifactId>
42+
<version>0.39.0-beta</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>commons-cli</groupId>
46+
<artifactId>commons-cli</artifactId>
47+
<version>1.3.1</version>
48+
</dependency>
49+
</dependencies>
50+
</project>

0 commit comments

Comments
 (0)