<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Send Command to a linux host using workflows in Automations</title>
    <link>https://community.dynatrace.com/t5/Automations/Send-Command-to-a-linux-host-using-workflows/m-p/262574#M1882</link>
    <description>&lt;P&gt;You can use a server in your host to allow restarting the process.&lt;BR /&gt;I do prefer the Ansible solution as it is more scalable than this approach.&lt;BR /&gt;But something like this should work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import ssl
from http.server import HTTPServer, BaseHTTPRequestHandler
import subprocess

class RequestHandler(BaseHTTPRequestHandler):
    def do_POST(self):
        if self.path == '/restart-process':
            # Add authentication check here if needed
            self.restart_process()
        else:
            self.send_error(404, "Not Found")

    def restart_process(self):
        try:
            # Replace this with your actual restart command
            subprocess.run(["systemctl", "restart", "your-process-name"], check=True)
            self.send_response(200)
            self.send_header('Content-type', 'text/plain')
            self.end_headers()
            self.wfile.write(b"Process restarted successfully")
        except subprocess.CalledProcessError:
            self.send_error(500, "Failed to restart process")

def run_server():
    server_address = ('your-linux-host.internal', 443)  # Use the appropriate hostname and port
    httpd = HTTPServer(server_address, RequestHandler)
    
    # SSL wrapping
    context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
    context.load_cert_chain('server.crt', 'server.key')
    httpd.socket = context.wrap_socket(httpd.socket, server_side=True)
    
    print(f"Server running on https://{server_address[0]}:{server_address[1]}")
    httpd.serve_forever()

if __name__ == '__main__':
    run_server()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;server.crt&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;and&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;server.key&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;used for HTTPS&lt;BR /&gt;&amp;nbsp;The&amp;nbsp;restart_process&amp;nbsp;method uses&amp;nbsp;subprocess.run&amp;nbsp;to execute the restart command. Replace&amp;nbsp;"your-process-name"&amp;nbsp;with the actual process name&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Nov 2024 09:32:22 GMT</pubDate>
    <dc:creator>PacoPorro</dc:creator>
    <dc:date>2024-11-15T09:32:22Z</dc:date>
    <item>
      <title>Send Command to a linux host using workflows</title>
      <link>https://community.dynatrace.com/t5/Automations/Send-Command-to-a-linux-host-using-workflows/m-p/261737#M1866</link>
      <description>&lt;P&gt;Good day everyone, I am currently working with EdgeConnect because I want to send commands to a Linux host to restart a process. I remember seeing an EdgeConnect application for workflows, is that correct?&lt;/P&gt;&lt;P&gt;If that app no longer exists, how can I send that command to my host through a workflow?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2024 16:55:25 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Automations/Send-Command-to-a-linux-host-using-workflows/m-p/261737#M1866</guid>
      <dc:creator>Jorge3229</dc:creator>
      <dc:date>2024-11-06T16:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: Send Command to a linux host using workflows</title>
      <link>https://community.dynatrace.com/t5/Automations/Send-Command-to-a-linux-host-using-workflows/m-p/261758#M1867</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/58775"&gt;@Jorge3229&lt;/a&gt;&amp;nbsp;using ansible does the trick.&lt;/P&gt;&lt;P&gt;&lt;A href="https://xxxxxxxx.apps.dynatrace.com/ui/apps/dynatrace.hub/browse/all?search=ansible&amp;amp;details=dynatrace.redhat.ansible" target="_blank"&gt;https://xxxxxxxx.apps.dynatrace.com/ui/apps/dynatrace.hub/browse/all?search=ansible&amp;amp;details=dynatrace.redhat.ansible&lt;/A&gt;&lt;/P&gt;&lt;P&gt;with this you can create an action to launch a job template in Red Hat Ansible Automation Controller.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2024 03:19:53 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Automations/Send-Command-to-a-linux-host-using-workflows/m-p/261758#M1867</guid>
      <dc:creator>DanielS</dc:creator>
      <dc:date>2024-11-07T03:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: Send Command to a linux host using workflows</title>
      <link>https://community.dynatrace.com/t5/Automations/Send-Command-to-a-linux-host-using-workflows/m-p/262564#M1879</link>
      <description>&lt;P&gt;You can take a look at Kubernetes Automation: &lt;A href="https://docs.dynatrace.com/docs/platform-modules/automations/workflows/actions/kubernetes-automation" target="_blank"&gt;https://docs.dynatrace.com/docs/platform-modules/automations/workflows/actions/kubernetes-automation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;This leverages EdgeConnect on Kubernetes, and you can leverage &lt;A href="https://docs.dynatrace.com/docs/platform-modules/automations/workflows/actions/kubernetes-automation/kubernetes-workflow-actions" target="_self"&gt;several actions&lt;/A&gt; (e.g., apply configuration or restart deployment) to perform certain tasks.&lt;/P&gt;&lt;P&gt;In theory you can also try to use a Kubernetes job/workload to execute a command on another host.&lt;/P&gt;&lt;P&gt;Please also refer to &lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/35788"&gt;@DanielS&lt;/a&gt; post about using Red Hat Ansible, that's a perfect alternative.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 08:44:15 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Automations/Send-Command-to-a-linux-host-using-workflows/m-p/262564#M1879</guid>
      <dc:creator>christian_kreuz</dc:creator>
      <dc:date>2024-11-15T08:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: Send Command to a linux host using workflows</title>
      <link>https://community.dynatrace.com/t5/Automations/Send-Command-to-a-linux-host-using-workflows/m-p/262574#M1882</link>
      <description>&lt;P&gt;You can use a server in your host to allow restarting the process.&lt;BR /&gt;I do prefer the Ansible solution as it is more scalable than this approach.&lt;BR /&gt;But something like this should work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import ssl
from http.server import HTTPServer, BaseHTTPRequestHandler
import subprocess

class RequestHandler(BaseHTTPRequestHandler):
    def do_POST(self):
        if self.path == '/restart-process':
            # Add authentication check here if needed
            self.restart_process()
        else:
            self.send_error(404, "Not Found")

    def restart_process(self):
        try:
            # Replace this with your actual restart command
            subprocess.run(["systemctl", "restart", "your-process-name"], check=True)
            self.send_response(200)
            self.send_header('Content-type', 'text/plain')
            self.end_headers()
            self.wfile.write(b"Process restarted successfully")
        except subprocess.CalledProcessError:
            self.send_error(500, "Failed to restart process")

def run_server():
    server_address = ('your-linux-host.internal', 443)  # Use the appropriate hostname and port
    httpd = HTTPServer(server_address, RequestHandler)
    
    # SSL wrapping
    context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
    context.load_cert_chain('server.crt', 'server.key')
    httpd.socket = context.wrap_socket(httpd.socket, server_side=True)
    
    print(f"Server running on https://{server_address[0]}:{server_address[1]}")
    httpd.serve_forever()

if __name__ == '__main__':
    run_server()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;server.crt&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;and&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;server.key&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;used for HTTPS&lt;BR /&gt;&amp;nbsp;The&amp;nbsp;restart_process&amp;nbsp;method uses&amp;nbsp;subprocess.run&amp;nbsp;to execute the restart command. Replace&amp;nbsp;"your-process-name"&amp;nbsp;with the actual process name&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 09:32:22 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Automations/Send-Command-to-a-linux-host-using-workflows/m-p/262574#M1882</guid>
      <dc:creator>PacoPorro</dc:creator>
      <dc:date>2024-11-15T09:32:22Z</dc:date>
    </item>
  </channel>
</rss>

