There are a lot of rats in my house. What is the ruling of killing this animal, if they have infested my house for it could jeopardize my family’s health?
Alhamdulillah, praise and thanks to Allah for the countless blessings He has blessed us all with. Blessings and salutations to the Prophet Muhammad PBUH, his family, companions and all those that follow his teachings to the day of judgement.
Rat falls under the category of animals that are sunnah to be killed for it is a filthy and dirty animal and it could cause harm to humans. It is also included as al-Fawasiq al-Khams (five pests), according to a hadith from the Prophet PBUH. From Aisyah RA, the Prophet PBUH said:
خَمْسٌ فَوَاسِقُ يُقْتَلْنَ فِي الْحَرَمِ الْعَقْرَبُ وَالْفَارَةُ وَالْحُدَيَّا وَالْغُرَابُ وَالْكَلْبُ الْعَقُورُ
“Five are the vicious and harmful things which should be killed even within in the state of Ihram: rat, scorpion, crow, ‘kite’ (predatory bird similar to eagle) and voracious dog.”
Sahih Muslim (1198)
Al-Imam Malik Rahimahullah said that the hadith sanctions the killing of these animals due to the nature of these hams fawasiq that disturb and harm humans, thus it is permissible to kill them even in ihram. 
Hence, even when someone is in ihram, it is permissible to kill these animals, it is also permissible to kill these animals when someone is not in ihram.
Syeikh Nawawi al-Bantani Rahimahullah state in his book, Kasyifah al-Saja Syarh Safinah al-Naja, it is permissible to kill animals that bring harm, or its nature is the same as al-Fawasiq al-Khams. The reason is, it is filthy, dirty and harmful. 
Although it is permissible to kill these khams fawasiq, there are manners and guidelines set in Islam in killing anything. This is in accordance to a hadith of Prophet PBUH:
إِنَّ اللَّهَ كَتَبَ الإِحْسَانَ عَلَى كُلِّ شَىْءٍ فَإِذَا قَتَلْتُمْ فَأَحْسِنُوا الْقِتْلَةَ وَإِذَا ذَبَحْتُمْ فَأَحْسِنُوا الذَّبْحَ وَلْيُحِدَّ أَحَدُكُمْ شَفْرَتَهُ فَلْيُرِحْ ذَبِيحَتَهُ
“Verily Allah has prescribed ihsan (proficiency, perfection) in all things. So if you kill then kill well; and if you slaughter, then slaughter well. Let each one of you sharpen his blade and let him spare suffering to the animal he slaughters.”
Sahih Muslim (1955)
Thus, practising ihsan in everything, as stated by the above hadith includes the killing of rats, even if they are considered as pests. Syeikh al-Mulla Ali al-Qari states that proficiency in killing is finding the best way to kill and inflicting the least pain and suffering. 
Even when trapping the rat, when he finds that a rat is trapped in the cage or trap he set, he should quickly kill it to avoid prolonged suffering on the animal and practising what has been commanded by the Prophet PBUH to practise ihsan in everything that we do.
The ruling for killing pests is permissible for their harmful nature for humans and the environment. Although syara’ permits the killing of these pests, it is also commanded for us to practise ihsan when killing these pests as discussed above.
When someone sets a trap, he has to check it frequently and quickly kill the rats (or other pests) trapped in it. If there is a valid reason such as when he has to sleep or work, that results in his inability to check the trap, then it is not an error on his part. Furthermore, we should always take care of the cleanliness of our house to prevent and avoid these fawasiq from infesting our homes. Wallahua’lam.