Why do bad things happen to good people? Why do we see persons who we know are evil doing well, being happy and successful? Is God not really in charge of what happens? Is he ignorant of evil or not truly omnipotent? What is divine justice?
The Book of Job is called one of the "wisdom literature" of the Old Testament, the others being Psalms and Proverbs. From my reading, it appears to be quite poetic and rich in metaphors. This book is thought to have been written in the 5th century BC in the post-Exilic period.
To give a synopsis, this is the story of a man named Job who has his faith tested in the severest sense. Job is very successful, has a large, happy family and is pious and thankful toward God. Satan says to God that Job is only pious because he is prosperous and well treated. God decides to wager (?) Satan that this is not true and he allows Satan to do terrible things to Job. Satan steals all of Job's livestock, destroys his livelihood, kills all his children and then gives Job a horrible, disfiguring disease. Job's wife tells him to curse God and die.
About then, three of Job's friends show up and they have a long dialogue with Job about why God would do this to someone who is good and pious. What is communicated to us is one of the fundamental beliefs in the Judeo-Christian-Muslim faith. God tests us with adversity, he allows bad things to happen to good people AND good things to happen to bad people. However, the good people shall be rewarded in the end.
Job has a difficult time understanding why God would do this to him, one of his faithful servants.
Eventually God reveals himself and tells Job that he cannot possibly understand God's reasons. God says that Job cannot comprehend the breadth of the Earth, send forth lightning, provide food for all beasts or know the heavens above. How then can Job understand the great plans of God?
In the end, God rewards Job for his patience and faith by granting him ten more children, more livestock and a much longer life. However, I do wonder if this is suitable recompense for all his suffering, including the death of his first ten children. In addition, why would God need to make a wager with Satan. What does that prove? God already knows that Job is faithful and steadfast and he will never be able to convince Satan of that. Of course the theologians would say that I cannot possibly understand what God's plan is...how convenient.