Fluctuations relation and external thermostats: an application to granular materials