Mishkat al-Masabih 115
Ibn ad-Dailami said:
I went to Ubayy b. Ka‘b and said to him, “I am confused about the divine decree, so tell me something by means of which God may remove the confusion from my mind.” He replied, “Were God to punish everyone in the heavens and the earth He would do so without being unjust to them, and were He to show mercy to them His mercy would be much better than their actions merited. Were you to spend in support of God’s cause an amount of gold equivalent to Uhud, God would not accept it from you till you believed in the divine decree and knew that what has come to you could not miss you and that what has missed you could not come to you. Were you to die believing anything else you would enter hell.” He said: I then went to ‘Abdallah b. Mas'ud and he said something to the same effect. I next went to Hudhaifa b. al-Yaman and he said something to the same effect. I next went to Zaid b. Thabit and he told me something from the Prophet to the same effect. 

Ahmad, Abu Dawud and Ibn Majah transmitted it.
وَعَنِ ابْنِ الدَّيْلَمِيِّ قَالَ: أَتَيْتُ أُبَيَّ بْنَ كَعْبٍ فَقُلْتُ لَهُ: قَدْ وَقَعَ فِي نَفْسِي شَيْء من الْقدر فَحَدثني بِشَيْء لَعَلَّ الله أَن يذهبه من قلبِي قَالَ لَو أَن الله عَذَّبَ أَهْلَ سَمَاوَاتِهِ وأَهْلَ أَرْضِهِ عَذَّبَهُمْ وَهُوَ غَيْرُ ظَالِمٍ لَهُمْ وَلَوْ رَحِمَهُمْ كَانَتْ رَحْمَتُهُ خَيْرًا لَهُمْ مِنْ أَعْمَالِهِمْ وَلَوْ أَنْفَقْتَ مِثْلَ أُحُدٍ ذَهَبًا فِي سَبِيلِ اللَّهِ مَا قَبِلَهُ اللَّهُ مِنْكَ حَتَّى تُؤْمِنَ بِالْقَدَرِ وَتَعْلَمَ أَنَّ مَا أَصَابَكَ لَمْ يَكُنْ لِيُخْطِئَكَ وَأَنَّ مَا أَخْطَأَكَ لَمْ يَكُنْ لِيُصِيبَكَ وَلَوْ مُتَّ عَلَى غَيْرِ هَذَا لَدَخَلْتَ النَّارَ قَالَ ثُمَّ أَتَيْتُ عَبْدَ اللَّهِ بْنَ مَسْعُودٍ فَقَالَ مِثْلَ ذَلِكَ قَالَ ثُمَّ أَتَيْتُ حُذَيْفَةَ بْنَ الْيَمَانِ فَقَالَ مثل ذَلِك قَالَ ثُمَّ أَتَيْتُ زَيْدَ بْنَ ثَابِتٍ فَحَدَّثَنِي عَنِ النَّبِيِّ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ مِثْلَ ذَلِكَ. رَوَاهُ أَحْمَدُ وَأَبُو دَاوُدَ وَابْنُ مَاجَهْ