Skip to content

Commit

Permalink
Creating sample for StackDriver Alerts.
Browse files Browse the repository at this point in the history
  • Loading branch information
dzlier-gcp committed Mar 16, 2018
1 parent 5559f18 commit 8b955c8
Show file tree
Hide file tree
Showing 5 changed files with 636 additions and 0 deletions.
48 changes: 48 additions & 0 deletions monitoring/v3/README.md
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
2 changes: 2 additions & 0 deletions monitoring/v3/manage_alerts_sample.sh
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"
85 changes: 85 additions & 0 deletions monitoring/v3/pom.xml
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>
Loading

0 comments on commit 8b955c8

Please sign in to comment.