Hello @Akash Verma ,
You can use Azure CLI, Azure PowerShell, ARM, and REST API to configure programmatic way.
Enable diagnostics setting on HDInsight Cluster
This article provides details on creating and configuring diagnostic settings to send platform metrics and platform logs to different destinations using Azure Portal, Azure PowerShell, ARM template, REST API and Azure policy.
Enable Azure Monitor for the HDInsight cluster
This article helps on how to enable Azure Monitor logs to monitor Hadoop cluster operations in HDInsight using Azure Portal, Azure PowerShell & Azure CLI.
Enable NSG Flow Logs
This article helps to enable NSG Flow logs using Azure Portal, PowerShell, CLI, REST and ARM Template to enable NSG Flow logs:
NSG Modifications (Rule Add, delete, update etc)
For HDInsight: This article provides examples and code samples for creating and configuring Azure Virtual Networks. To use with Azure HDInsight clusters. Detailed examples of creating network security groups (NSGs) and configuring DNS are presented.
In General: This article to helps to create, change, or delete a network security group via Azure Portal, PowerShell and Azure CLI.
Hope this helps. Do let us know if you any further queries.
----------------------------------------------------------------------------------------
Do click on "Accept Answer" and Upvote on the post that helps you, this can be beneficial to other community members.