How to write my own "Datasource Program" aka "Special Agent"

I am not looking for local checks, I want my own “Datasource Program” aka “Special Agent” in cause I can’t install a check_mk agent on the target system.

A special agent needs e.g. an agent_foobar in ~/local/check_mk/agents/special/
that outputs the e.g. <<<foobar>>> section.

I guess the special_agent needs to be registered somehow and it needs some
web page snippets to be configurable.

I am looking for documentation how to do that, or a simple example.