How to push serial console output logs to Stackdriver and set alerts in GCP

GCP provides to use serial consoles for all the VMs. Every VM have 4 serial ports. Serial ports are similar to Termal windows which supports both input and output. Its completely in full text based windows, no GUI. These ports are will help to troubleshoot Boot manager or GRUB related issues.

What are the logs we can see from Serial Console:

OS logs (During sysprep)

BIOS

System level entries

Most of the system level entries are captured in Serial Port 1.

To read more details about Serial console, please refer the official documentation from GCP.

Why we are checking this logs?

We were in a process of setting an autoscaling group in a private subnet and use NAT for external internet communication. During the autoscale the Windows image(fully hardened) will be launched. Once the sysprep has been done, then this will communicate to the Microsoft KMS server and get the new Protect key and Activate the Windows OS. But in our case the communication to the KMS was failing and the Windows is not activated during the launch.

This complete information will be provided by the Serial Console. So we decided to push the logs to StackDriver and set the alert if the windows is not activated.