“Before I was afflicted I went astray, but now have I kept your word.
It is good for me that I have been afflicted, that I might learn your statutes.
I know, O LORD, that your judgments are right,
and that you in faithfulness have afflicted me.”
Psalm 119:67, 71, 75
These three verses became precious to my soul after Jesus spoke to me in 1981, telling me that it is God who chastens His children, not the Devil. David was able to see good purposes for his afflictions, and give thanks for them, only because he knew that God, not Baal, was the One afflicting him.