@absarcompass, This depends on what agent you're using. In NSClient you can make a script and put it into a scripts folder. Here's an example:
https://assets.nagios.com/downloads/nag ... ios-XI.pdf It's not exactly what you want but it'll walk you through the process of creating and configuring a custom script to run with NSClient.
Also, I don't know the whole plan of action but implementing this technique might be a little overkill. Why not build a script locally with a simple ping command from one server to another?
Also, Nagios XI has event handler option. So you probably already monitor host A and B with XI, you can add a custom event handler script to do something when server X goes down.
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
And the first link has more info on event handlers as well, if you scroll to the bottom.