-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating sample for StackDriver Alerts.
- Loading branch information
1 parent
5559f18
commit 8b955c8
Showing
5 changed files
with
636 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Cloud Monitoring Sample | ||
|
||
Simple command-line program to demonstrate connecting to the Google | ||
Monitoring API to retrieve and modify Alerts data. | ||
|
||
## Prerequisites to run locally: | ||
|
||
* [Maven 3](https://maven.apache.org) | ||
* [GCloud CLI](https://cloud.google.com/sdk/gcloud/) | ||
* Create a Cloud project | ||
|
||
# Set Up Your Local Dev Environment | ||
|
||
Create local credentials by running the following command and following the oauth2 flow: | ||
|
||
gcloud beta auth application-default login | ||
|
||
To run: | ||
|
||
* `mvn clean install` | ||
* `./manage_alerts_sample.sh <YOUR-PROJECT-ID> <command> <args> | ||
|
||
## Running on GCE, GAE, or other environments | ||
|
||
On Google App Engine, the credentials should be found automatically. | ||
|
||
On Google Compute Engine, the credentials should be found automatically, but require that | ||
you create the instance with the correct scopes. | ||
|
||
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 | ||
|
||
If you did not create the instance with the right scopes, you can still upload a JSON service | ||
account and set `GOOGLE_APPLICATION_CREDENTIALS` as described below. | ||
|
||
## Using a Service Account | ||
|
||
In non-Google Cloud environments, GCE instances created without the correct scopes, or local | ||
workstations if the `gcloud beta auth application-default login` command fails, use a Service | ||
Account by doing the following: | ||
|
||
* Go to API Manager -> Credentials | ||
* Click 'New Credentials', and create a Service Account or [click here](https://console.cloud.google | ||
.com/project/_/apiui/credential/serviceaccount) | ||
Download the JSON for this service account, and set the `GOOGLE_APPLICATION_CREDENTIALS` | ||
environment variable to point to the file containing the JSON credentials. | ||
|
||
|
||
export GOOGLE_APPLICATION_CREDENTIALS=~/Downloads/<project-id>-0123456789abcdef.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env bash | ||
mvn exec:java -Dexec.mainClass=AlertSample -Dexec.args="$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<!-- | ||
Copyright 2016 Google Inc. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.example.monitoring</groupId> | ||
<artifactId>monitoring-google-cloud-v3-samples</artifactId> | ||
<version>0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<!-- | ||
The parent pom defines common style checks and testing strategies for our samples. | ||
Removing or replacing it should not affect the execution of the samples in anyway. | ||
--> | ||
<parent> | ||
<groupId>com.google.cloud.samples</groupId> | ||
<artifactId>shared-configuration</artifactId> | ||
<version>1.0.8</version> | ||
</parent> | ||
|
||
<properties> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<project.http.version>1.22.0</project.http.version> | ||
<project.oauth.version>1.22.0</project.oauth.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<skipTests>true</skipTests> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>google-cloud-monitoring</artifactId> | ||
<version>0.39.0-beta</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>joda-time</groupId> | ||
<artifactId>joda-time</artifactId> | ||
<version>2.9.6</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.8.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-cli</groupId> | ||
<artifactId>commons-cli</artifactId> | ||
<version>1.3.1</version> | ||
</dependency> | ||
|
||
<!-- Test Dependencies --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.jcabi</groupId> | ||
<artifactId>jcabi-matchers</artifactId> | ||
<version>1.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.truth</groupId> | ||
<artifactId>truth</artifactId> | ||
<version>0.30</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Oops, something went wrong.