Didn't ninjutsu begin as a resistance movement in small villages being harrassed by the emperor's soldiers? I think you can call that peacekeeping.
There is little in the way of real historical record of the origins of
shinobi or
ninja, which are effectively the same thing. The earliest known details are of their use as spies and saboteurs during the Sengoku Period, from about 1467-1615. What is known is that they were usually lower classes recruited for dirty deeds; mainly spying, sabotage, and terror. These deeds were considered beneath the samurai classes and the ninja were recruited for pay, which was unseemly to a samurai. However,
ronin, the masterless samurai, from defeated clans, often found themselves forced into such things, though usually things like bodyguards and assassins.
Most of what is perpetuated about ninja, much like
yakuza codes of honor and position, is based on romantic fantasy, in literature and other entertainment, much like the myth of the Cowboy and the Old West; particularly in the West, as the chief mechanism for conveying those subjects is literature and other entertainment. It is believed that the idea of the black suits came from kabuki theater, as anything that was meant to be "unseen" was draped in black, including stagehands and "invisible actors." This is also where the myths of ninjas as assassins seems to originate, as characters would be assassinated by an unseen foe, draped in black.
The lower classes were conscripted to be spearmen/foot soldiers (
ashigaru) in the armies of the nobles, as only samurai were legally allowed to carry swords, in certain periods (including the Tokugawa Shogunate). They were the cannon fodder of the armies, used to hurl bodies at the enemy, much as in other armies. Cavalry provided the heavy weapons, though well used spearmen could defend against cavalry attacks, by clustering in hedges, with spears thrust outward to causes horses to veer away (Europeans used similar tactics, though it was more effective with longer pikes). Also, when firearms appeared in Japan, in the 1500s (brought by the Portugese), they were mostly carried by
ashigaru, as they were generally not considered dignified enough for the samurai. The
ashigaru were usually the tenants of the noble landlords, the peasants. These would also serve as defenders if their villages or farms were attacked; so, that is more your source for the militias that defended small villages.
The Sengoku Period is filled with wars and political turmoil, which fuels a lot of the literary fantasies and legends, that have been perpetuated as fact, both within Japan and outside. Much like European codes of chivalry and stories of the Crusades were more propaganda and romantic notions, the same holds true for much of the reality of the samurai and
bushido. The philosophy was hard to live up to and the reality is that those who stayed alive longer usually did so by not trying to adhere to codes that hamstrung you in battle. After the battle, you can commission all the history you want to show your virtuous victory in your heroic crusade, especially when the Opposition Response is dead.