saurabh umathe
saurabh umathe

Reputation: 395

How can I receive custom email notifications when a VM instance is created in my GCP Project

I understand there are ways to create alerts based on certain metrics and get notified through various channels, however, We did not find any way to get notified when a new resource (VM instance in our case) is added in our GCP project.

This is very useful to keep the track since we have multiple users with the access to create resources.

Also, it would send us an alert when GKE is resized to more nodes.

Upvotes: 2

Views: 1761

Answers (1)

Fariya Rahmat
Fariya Rahmat

Reputation: 3220

You can get email notifications on creating a new VM by following these steps:

1)Create a log based metric in console

    a)Go to logging->log based metric->create metric
    b)Select counter in metric type.
    c) In details give any log name(ex:user/creation).
    d)In filter provide the following:
        resource.type:"gce_instance"
        protoPayload.methodName:"compute.instances.insert"
        Operation.first:"true”
    e)Let the other fields  be default 
    f)Then,create the metric

    

2)Create an alert policy :

    a)Go to monitoring->alerting
    b)Select create policy->Add condition
         In Find resource type and metric field:
            Resource type:VM instance   
            Metric:logging/user/user/creation   (logging/user /<logname in step 1>)
            (both Resource type & Metric in same field)
        In Filter:
            project_id=Your project id
        In configuration:
            Condition triggers if:All time series violate
            Condition: is above , threshold: 0,for:most recent value
    c)Let the other fields  be default .
    d)Add and click on next
    e)In Notifications Channels go to Manage notifications channels this will redirect you to a new 
      page in that select email -> Add new(provide the email where you want to get notifications & 
      display name)
    f)Refresh the previous tab now you can see your display name in notifications channel and check 
      the box of display name ,click ok 
    g)Check the box of Notify on incident closure & click Next
    h) Provide alert name & save the changes.

I have tested this in my environment and I got this alert enter image description here

Upvotes: 4

Related Questions