I saw the Prophet ﷺ on the day of the Trench carrying away dirt until the dust covered the hair of his chest, and he was a man with thick hair. He was reciting the verses of Abdullah bin Rawaha,"O Allah, were it not for You we would not have been guided, nor would we have given charity, nor would we have prayed. So send down tranquility upon us, and make our feet firm if we meet the enemy. The enemies have transgressed against us, when they desire discord we refuse."He raised his voice with these words.
رأيت النبي ﷺ يوم الخندق وهو ينقل التراب حتى وارى التراب شعر صدره- وكان رجلا كثير الشعر- وهو يرتجز برجز عبد الله بن رواحة: اللهم لولا أنت ما اهتدينا ولا تصدقنا ولا صلينا فأنزلن سكينة علينا وثبت الأقدام إن لاقينا إن الأعداء قد بغوا علينا إذا أرادوا فتنة أبينا يرفع بها صوته.
Bukhari related it in the Book of Jihad (3034) - and this is his wording - and Muslim in the Book of Jihad (1803:125), both through the route of Abu Ishaq, from Bara, as mentioned.As for the narrations in which the Prophet ﷺ is said to have recited some verses of poetry without observing their proper meter, these are all defective. The Prophet ﷺ was the most eloquent of the Arabs, so such a matter would not have escaped him, and it is unlikely that this occurred from him ﷺ.Poetry, when free from obscenities, reprehensible content, and calls to pre-Islamic ways, may be composed, memorized, and recited without any harm. In fact, it is praiseworthy and desirable, for it instills virtues in people's hearts, praises the Prophet ﷺ, calls to Islam, and defends it. The Prophet ﷺ used to encourage the companions to defend Islam through their poetry, and he would ask them to recite it and would listen to them.The discussion of this matter is treated at length in the tafsir of Surah Shuara, verses [224–227].