Add teardown to flush elasticsearch on agent shutdown

Prior to this, some events could be lost if logstash was shutdown.