The Messenger of Allah ﷺ said, "Whoever sees someone afflicted and says, 'Praise be to Allah who has spared me from what He has tested you with and favored me greatly over much of what He has created,' will not be struck by that affliction."
قال رسول الله ﷺ: من رأى مبتلى فقال: الحمد لله الذي عافاني مما ابتلاك به، وفضلني على كثير ممن خلق تفضيلا لم يصبه ذلك البلاء.
Tabarani related it in Al-Awsat — Majma Bahrayn (4600) via Zakariya bin Darir, who said, Shababa bin Sawwar told us, Mughira bin Muslim told us, from Ayub, from Nafi, from Ibn Umar, who said, and he mentioned it. Tabarani said, "No one narrated it from Ayub except Mughira, and no one narrated it from him except Shababa, Zakariya alone transmitted it."I say, Zakariya bin Yahya Darir was narrated from by a group of trustworthy narrators, and Khatib gave him a biographical entry in his history (7/457), without mentioning any criticism or endorsement of him.There is another chain for it, which Tabarani related in Al-Duaa (798), and from him Abu Naeem in Hilyah (5/13), via Marwan bin Muhammad Tatari, who said, Walid bin Utba told us, Muhammad bin Suqa told us, from Nafi, from Ibn Umar, and he mentioned it. Taking both chains together, the hadith becomes hasan.Something of similar meaning was narrated from Umar, related by Tirmidhi (3431), but its chain contains Amr bin Dinar, the steward of the household of Zubayr, who is daif. It was also narrated from Abu Hurairah, but there is some criticism regarding its chain.