One of the supplications of Prophet David ﷺ was: "Glory be to the One who brings forth gratitude through His gifts, and brings forth supplication through hardships."
كَانَ مِنْ دُعَاءِ دَاوُدَ عَلَيْهِ السَّلَامُ سُبْحَانَ مُسْتَخْرِجِ الشُّكْرِ بِالْعَطَاءِ وَمُسْتَخْرِجِ الدُّعَاءِ بِالْبَلَاءِ