  We develop an abstract theory to obtain Harnack inequality for non
homogeneous PDEs in the setting of quasi metric spaces. The main idea is to
adapt the notion of double ball and critical density property given by Di
Fazio, Guti\'errez, Lanconelli, taking into account the right hand side of the
equation. Then we apply the abstract procedure to the case of subelliptic
equations in non divergence form involving Grushin vector fields and to the
case of X-elliptic operators in divergence form.
