It's an oil level sensor if the oil level is too low the spark will be cut to kill the engine ,make sure your oil is good and the right level on the dipstick then disconnect the yellow wire and see how long the motor runs then plug the wire together and if the motor cuts out you know there is a problem with the switch or oil alert unit..(8 and 6 in the image below )