WASHINGTON — The Department of Homeland Security is gathering intelligence from paid undercover informants inside the migrant caravan that is now reaching the California-Mexico border as well as monitoring the text messages of migrants, according to two DHS officials.

The 4,000 migrants, mainly from Honduras, have used WhatsApp text message groups as a way to organize and communicate along their journey to the California border, and DHS personnel have joined those groups to gather that information.

The intelligence gathering techniques are combined with reports from DHS personnel working in Mexico with the government there in an effort to keep tabs on the caravan's size, movements and any potential security threats.

On Monday, DHS officials told reporters that their intelligence on Sunday night had indicated that a group of migrants wanted to run through the car lanes of a border crossing near San Diego. Customs and Border Protection shut down all northbound lanes of the crossing from 3 a.m. to 6 a.m. as a result. However, the ambush was never attempted.

Paying informants, placing officers in the region or monitoring the communications of non-U.S. citizens is not illegal, said John Cohen, former acting undersecretary of intelligence for DHS, but it does raise some concerns about the allocation of resources.

"Those resources have to come from some place. They are not being devoted to thwarting terrorist threats, mass shootings, mailed fentanyl coming into the country or cyberattacks," said Cohen.

Cohen said the caravan presents a logistical and humanitarian issue, but because the vast majority of its members want to present themselves legally to claim asylum, it is not wise to devote a significant amount of intelligence resources to it.

"I find it hard to believe that the highest risk facing this nation comes from this caravan," Cohen said.

It is not known how much money DHS is spending on the intelligence gathering inside the caravan.

In a statement, DHS Spokeswoman Katie Waldman said, "While not commenting on sources or methods, it would be malpractice for the United States to be ignorant about the migrants — including many criminals — attempting to enter our country. We have an obligation to ensure we know who is crossing our borders to protect against threats to the Homeland and any indication to the contrary is misinformed."