Sayyiduna Ibn Abbas (may Allah be pleased with them both) said: The Messenger of Allah (peace and blessings be upon him) said to me: "O boy, guard (the rights of) Allah and He will guard you. Guard (the rights of) Allah and you will find Him before you. Recognise Allah in times of ease and He will recognise you in times of hardship. Know that what has reached you was not going to miss you, and what has missed you was not going to reach you. Know that if all of creation gathered together to give you something that Allah did not wish to give you, they would not be able to do it; or to turn away from you something that Allah intended to befall you, they would not be able to do that either. So when you ask, ask of Allah; and when you seek help, seek help from Allah. Know that victory comes with patience, relief comes with distress, and indeed with hardship comes ease. And know that the Pen has already written all that is to be."
Hadith Referenceالمعجم الكبير للطبراني / باب العين / 11197