How to generate API running when Stackdriver alert me? - google-cloud-functions

I am following this doc.
I know Cloud functions make an HTTP request to your function, run the following command.
https://cloud.google.com/functions/docs/
I'd like to run a API that created in advance when the Stackdriver alerts may be triggered. I have already defined simple custom log-based metrics in GCP.
For example, I create a Stackdriver Alert detecting an unexpected error GAE log.
I want system to be down if that alert me.
It is possible to autmatic control APIs using StackDriver Alerting and Cloud funtions?  if you were me?

Related

authenticate google apps script to use google cloud run instance

I've got a Google Apps Script attached to a Google Sheet that is triggered when a new entry comes in. I've also got a Google Cloud Run instance for a Flask app that I access through an end-point.
Currently it allows unauthenticated invocations but I want to only allow authenticated invocations. How do I go about doing this? I can't access the metadata server as its outside of GCP and the Calling From Outside GCP suggests following the Identity-Aware Proxy sample code however IAP does not work for Cloud Run...
Is there any simple way of doing this?

Server error occurred at DriveApp.createFile

Every time I'm trying to manually invoke this test function in my script I get Server Error occurred. Please wait and try again (in a red bar on top of the editor window).
My original intention was to save a blob with createFile(blob) in my Web App, but it just fails with no error output, so I created this minimal test function.
function testgdrive()
{
var gdrive_file =
DriveApp.createFile("testfile","testcontents",MimeType.PLAIN_TEXT);
}
EDIT: This happens both on old Rhino engine and the new V8 engine as well.
The Web App is being deployed as a Google Sheets script on my basic (free) GSuite account.
It is a Google Cloud project, as I wasn't able to get any logs for Web App executions in the Standard mode at all.
For server errors such as
Server Error occurred. Please wait and try again
Creating/switching over to a new project may resolve the issue.

Script to clean disk on GCP

I have an alert in Stackdriver for when disk usage is above 90%. Is it possible to create a script that cleans a specific folder whenever this alert is raised?
TL;DR: Not advisable to do so.
Is always a better idea to properly manage the data on your VM. You can use logrotate to get rid of old logs.
If you really really want execute a script when an alert is triggered, you can use a Webhook and tool like Hookdoo so when Stackdriver triggers an alert, it will call Hookdoo (installed) on your VM and can configure Hookdoo to delete some files on your VM.

How can I view logs for previous deployed versions of my Google Cloud Function?

I have a bunch of logs in the Stackdriver Logging console for a Google Cloud Function called 'Daily_ETL_Job'. I edit the code and redeploy this function, keeping the same name. Once the redeployment succeeds, I can no longer view the previous versions' logs in the Logging console. I just see a blank screen with no logs at all.
Is there some other way to view these prior deployment invocation logs?

Google Calendar - getDefaultCalendar - no Authorization

CalendarApp.getDefaultCalendar() authorization
I have a similiar problem like the one below. As described in the answer, I started the jobs from script editor and granted the permissions. But I still get the error in my stackdriver error list and the action is not completed.
What can I do to authorize the script again or to get it running?