All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger. We ask Allaah to exalt his mention as well as that of his family and all his companions.
What is good in poetry is good, hence acceptable, and what is bad is bad, hence rejected. Poems about women’s beauty and charms are bad, and so are those which include expressions about ardent love and reunion of lovers and the like. They arouse desires, seduce weak persons, and simply waste time in what causes harm and yields no benefit.
However, if poetry contains behavioral advice or enthusiastic opinions that urge the reader to seek beneficial knowledge and do good, then this is approved and it is something which is desirable, like in the case of Jihaad, or entertaining one's company at times of hard work and travel. The Prophet recited some poetry while digging the trench, as well as prose and other comforting expressions of relief.
Hassaan also used to recite poetry defending the Prophet and urging Muslims to be steadfast.
Allaah knows best.