@@ -1800,6 +1800,23 @@ function _status(channel, state) {
1800
1800
} )
1801
1801
}
1802
1802
1803
+ function getIPAddress ( ) {
1804
+ const interfaces = os . networkInterfaces ( ) ;
1805
+ for ( const name of Object . keys ( interfaces ) ) {
1806
+ for ( const iface of interfaces [ name ] ) {
1807
+ if ( iface . family === 'IPv4' && ! iface . internal ) {
1808
+ return iface . address ;
1809
+ }
1810
+ }
1811
+ }
1812
+ return 'IP address not found' ;
1813
+ }
1814
+
1815
+
1816
+
1817
+
1818
+
1819
+
1803
1820
1804
1821
1805
1822
async function _debug ( channel , userName ) {
@@ -1813,28 +1830,6 @@ async function _debug(channel, userName) {
1813
1830
return value ;
1814
1831
}
1815
1832
1816
- function getHostIPAddress ( ) {
1817
- try {
1818
- const result = fs . readFileSync ( '/proc/net/route' , 'utf8' ) ;
1819
- const lines = result . split ( '\n' ) ;
1820
-
1821
- for ( const line of lines ) {
1822
- const columns = line . trim ( ) . split ( / \s + / ) ;
1823
-
1824
- // Look for the default route (Destination is 00000000)
1825
- if ( columns [ 1 ] === '00000000' ) {
1826
- const hexIp = columns [ 2 ] ; // Gateway IP is in the third column
1827
- const gatewayIp = hexToIp ( hexIp ) ;
1828
- return gatewayIp ;
1829
- }
1830
- }
1831
-
1832
- return 'Host IP address not found' ;
1833
- } catch ( err ) {
1834
- return 'Host IP address not found' ;
1835
- }
1836
- }
1837
-
1838
1833
function hexToIp ( hex ) {
1839
1834
return [
1840
1835
parseInt ( hex . slice ( 6 , 8 ) , 16 ) ,
@@ -1862,31 +1857,38 @@ async function _debug(channel, userName) {
1862
1857
} ;
1863
1858
1864
1859
const isDocker = isRunningInDocker ( ) ;
1860
+ const dockerStatus = isDocker ? 'Running in Docker' : 'Not running in Docker' ;
1865
1861
1866
- if ( isDocker ) {
1867
- if ( ! ipAddress ) {
1868
- const warningMessage = 'Make sure you have configured IP in the config.json' ;
1869
- logger . error ( warningMessage ) ;
1870
- ipAddress = warningMessage ;
1871
- }
1872
- } else {
1873
- ipAddress = getIPAddress ( ) ;
1874
- }
1862
+ let ipAddress = 'IP address not found' ;
1863
+
1864
+ ipAddress = getIPAddress ( ) ;
1875
1865
1876
- const dockerIPAddress = isDocker ? getHostIPAddress ( ) : null ;
1877
1866
const nodeVersion = JSON . stringify ( process . versions ) ;
1878
1867
1879
1868
xmlToJson ( url , async function ( err , data ) {
1880
- let sonosInfo = '' ;
1881
1869
if ( err ) {
1882
1870
logger . error ( 'Error occurred ' + err ) ;
1883
- sonosInfo = 'SONOS device is offline or not responding.' ;
1884
- } else {
1885
- sonosInfo =
1886
- '\n*Sonos Info*' +
1887
- '\nFriendly Name: ' + data . root . device [ 0 ] . friendlyName ;
1871
+ _slackMessage ( 'SONOS device is offline or not responding.' , channel ) ;
1872
+ return ;
1888
1873
}
1889
1874
1875
+ // Log the full XML response for debugging
1876
+ // logger.info('Full XML response: ' + JSON.stringify(data, null, 2));
1877
+
1878
+ const device = data . root . device [ 0 ] ;
1879
+ const sonosInfo =
1880
+ '\n*Sonos Info*' +
1881
+ `\nFriendly Name: ${ device . friendlyName [ 0 ] } ` +
1882
+ `\nRoom Name: ${ device . roomName [ 0 ] } ` +
1883
+ `\nDisplay Name: ${ device . displayName [ 0 ] } ` +
1884
+ `\nModel Description: ${ device . modelDescription [ 0 ] } ` +
1885
+ `\nModelNumber: ${ device . modelNumber [ 0 ] } ` +
1886
+ `\nSerial Number: ${ device . serialNum [ 0 ] } ` +
1887
+ `\nMAC Address: ${ device . MACAddress [ 0 ] || 'undefined' } ` +
1888
+ `\nSW Version: ${ device . softwareVersion [ 0 ] || 'undefined' } ` +
1889
+ `\nHW Version: ${ device . hardwareVersion [ 0 ] || 'undefined' } ` +
1890
+ `\nAPI Version: ${ device . apiVersion [ 0 ] || 'undefined' } ` ;
1891
+
1890
1892
const memoryUsage = process . memoryUsage ( ) ;
1891
1893
const formattedMemoryUsage = `\n*Memory Usage*:\n RSS: ${ Math . round ( memoryUsage . rss / 1024 / 1024 ) } MB` ;
1892
1894
@@ -1969,6 +1971,26 @@ async function _debug(channel, userName) {
1969
1971
type : 'mrkdwn' ,
1970
1972
text : '*Configuration Values*\n' + configValues
1971
1973
}
1974
+ } ,
1975
+ {
1976
+ type : 'divider'
1977
+ } ,
1978
+ {
1979
+ type : 'section' ,
1980
+ text : {
1981
+ type : 'mrkdwn' ,
1982
+ text : `*Docker Status*\n${ dockerStatus } `
1983
+ }
1984
+ } ,
1985
+ {
1986
+ type : 'divider'
1987
+ } ,
1988
+ {
1989
+ type : 'section' ,
1990
+ text : {
1991
+ type : 'mrkdwn' ,
1992
+ text : `*IP Address*\n${ ipAddress } `
1993
+ }
1972
1994
}
1973
1995
] ;
1974
1996
@@ -2006,6 +2028,9 @@ async function _debug(channel, userName) {
2006
2028
2007
2029
2008
2030
2031
+
2032
+
2033
+
2009
2034
async function _blacklist ( input , channel , userName ) {
2010
2035
_logUserAction ( userName , 'blacklist' ) ;
2011
2036
if ( channel !== global . adminChannel ) {
0 commit comments