Script to Monitor Google Cloud Unused External IP

Get notified when Google Cloud’s exterior static IP handle is not in use so you may launch it to economize.

I went by my Google Cloud Platform (GCP) bill and seen this:

It is not Google’s fault, it is mine. I reserved a static IP handle, however forgot to launch it after deleting the VM. It occurs, and I feel I am not alone.

I appeared round within the GCP console and could not discover an choice to warn when a static IP handle just isn’t in use. Maybe a request for a product function.

However I am not going to repeat the error.

Due to the Google Cloud SDK providing gcloud CLI that you should utilize in a script to do nearly something. I believed to jot down a script that runs day by day and stories when a static IP handle just isn’t in use. There are a number of methods to be notified and the primary handy strategy is electronic mail. However I haven’t got a mail server, so I needed to discover an alternate.

Inside a couple of minutes of looking out, I discovered Pushbullet. It’s a notification system that can be utilized to ship the alert to Chrome, Firefox, Safari, Opera, Android, iOS and Home windows. Virtually all the things. What else do I would like?

You possibly can guess that Pushbullet is now a requirement to get notified when you do not have a mail server on the server or wherever you need to run the gcloud command.

For those who resolve to move over to Pushbullet, create a free account, set the place you need to obtain notifications, and go to Settings to generate an entry token.

I assume you will have the entry token prepared and operating the gcloud command on the server.

Here is the little script. Create a file with the content material under, to illustrate <span class="s1">gcp-unused-ip-monitor.sh</span>

#!/bin/bash

if gcloud compute addresses listing | grep EXTERNAL | grep RESERVED ; then 
	curl -u $Access_TOKEN: https://api.pushbullet.com/v2/pushes -d kind=be aware -d title="Google Cloud IP NOT_INUSE" -d physique="Some exterior IP just isn't in use"
else :
fi

Remember to replace $Access_TOKEN with the precise worth.

Save the file and make it executable by giving execute permissions.

chmod 755 gcp-unused-ip-monitor.sh

Run the script manually to confirm the alert. When you have an unused IP handle, you’ll obtain a warning.

The above notification is from Chrome the place I configured Pushbullet to alert. However as talked about above, you may push the alert to cell units or one other browser. Select what you like.

Now we have now a working script after which we have to run it robotically day by day.

To schedule the script to run day by day, we use Crontab, which is obtainable on UNIX working programs.

Edit crontab with crontab -e and add the next

0 0 * * * $PATH/gcp-unused-ip-monitor.sh > /dev/null

Replace $PATH to the trail the place the script is positioned. The cron entry above will run the script each midnight. You possibly can regulate the period based mostly in your desire.

How simple is it?

After you have a notification, you may go to the GCP console and consider and launch the NOT IN USE IP handle.

I hope this little script saves you some $$$.

Leave a Comment

porno izle altyazılı porno porno