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

Maybe the following documentation helps:

https://checkmk.com/cms_datasource_programs.html#specialagents

Just take a look to the existing special agents which infos need to be provided.