Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
166 commits
Select commit Hold shift + click to select a range
af0517b
initial checkin
thesrinivas Aug 25, 2015
338a978
user-provided service detect
thesrinivas Aug 26, 2015
576ce30
user-provided service detect
thesrinivas Aug 26, 2015
243d47f
service detect
thesrinivas Aug 26, 2015
1b212b6
add debug logs
thesrinivas Aug 27, 2015
1216965
add debug logs
thesrinivas Aug 27, 2015
f06c00f
add debug log
thesrinivas Aug 27, 2015
b06c26d
correct access key name
thesrinivas Aug 27, 2015
613ca10
runtime env
thesrinivas Aug 28, 2015
2b48ee1
runtime env
thesrinivas Aug 28, 2015
252c770
runtime env
thesrinivas Aug 28, 2015
648a3dd
runtime env
thesrinivas Aug 28, 2015
cc8d999
runtime env
thesrinivas Aug 28, 2015
87b5907
runtime env
thesrinivas Aug 28, 2015
a4889a0
runtime env
thesrinivas Aug 28, 2015
836c227
runtime env
thesrinivas Aug 28, 2015
985bbb0
runtime env
thesrinivas Aug 28, 2015
e6d6a5d
runtime env
thesrinivas Aug 28, 2015
8e693d6
runtime env
thesrinivas Aug 28, 2015
077fc39
runtime env
thesrinivas Aug 28, 2015
6aba9e6
runtime env
thesrinivas Aug 28, 2015
0c2a222
runtime env
thesrinivas Aug 28, 2015
34c7668
runtime env
thesrinivas Aug 28, 2015
5128d89
runtime env
thesrinivas Aug 28, 2015
572d5b6
runtime env
thesrinivas Aug 28, 2015
33fac9e
runtime env
thesrinivas Aug 28, 2015
5dbed99
log lines
thesrinivas Aug 28, 2015
04c3c62
log lines
thesrinivas Aug 28, 2015
db17f7b
log lines
thesrinivas Aug 28, 2015
c28da29
logs
thesrinivas Aug 28, 2015
bad3217
logs
thesrinivas Aug 28, 2015
45ab2be
logs
thesrinivas Aug 28, 2015
9576383
logs
thesrinivas Aug 28, 2015
426d74c
logs
thesrinivas Aug 28, 2015
0ac3132
logs
thesrinivas Aug 28, 2015
78057e5
logs
thesrinivas Aug 28, 2015
9af6239
logs
thesrinivas Aug 28, 2015
f5aaaf3
logs
thesrinivas Aug 28, 2015
42c6b2f
logs
thesrinivas Aug 28, 2015
9f5412f
logs
thesrinivas Aug 28, 2015
e7b62d4
logs
thesrinivas Aug 28, 2015
3ae44a0
logs
thesrinivas Aug 28, 2015
dc35d3a
logs
thesrinivas Aug 28, 2015
9e07f3b
logs
thesrinivas Aug 28, 2015
d678475
logs
thesrinivas Aug 28, 2015
38b7934
logs
thesrinivas Aug 28, 2015
f5a9af6
logs
thesrinivas Aug 28, 2015
4545168
logs
thesrinivas Aug 28, 2015
d85b208
logs
thesrinivas Aug 28, 2015
1f594b1
logs
thesrinivas Aug 28, 2015
4f60f71
logs
thesrinivas Aug 28, 2015
6aa0013
logs
thesrinivas Aug 28, 2015
86040b8
logs
thesrinivas Aug 28, 2015
b9d9c08
logs
thesrinivas Aug 28, 2015
00e0d86
logs
thesrinivas Aug 28, 2015
6a41ee2
logs
thesrinivas Aug 28, 2015
e0a269a
logs
thesrinivas Aug 28, 2015
cbb9300
logs
thesrinivas Aug 28, 2015
075ca44
logs
thesrinivas Aug 28, 2015
c31f1f3
logs
thesrinivas Aug 28, 2015
5ece315
logs
thesrinivas Aug 28, 2015
a5c1609
logs
thesrinivas Aug 28, 2015
1b19967
hostname
Aug 28, 2015
4b3258c
logs
Aug 28, 2015
6b96d84
logs
Aug 29, 2015
4090cc1
logs
Aug 29, 2015
8a9bab0
logs
Aug 29, 2015
6b63e65
logs
Aug 29, 2015
ad7fabb
logs
Aug 29, 2015
d0f3afd
logs
Aug 29, 2015
6a99633
logs
Aug 29, 2015
9975aa9
logs
Sep 8, 2015
3987b0b
logs
Sep 8, 2015
aed49ab
logs
Sep 8, 2015
fb3501f
logs
Sep 8, 2015
7128785
logs
Sep 8, 2015
4e7c571
logs
Sep 8, 2015
03d4c76
logs
Sep 8, 2015
ee427a3
tier name and hostname change
Sep 9, 2015
9f8b276
add nodename
Sep 9, 2015
b284818
add nodename
Sep 9, 2015
b905ce4
add nodename
Sep 9, 2015
6c0bcdc
add nodename
Sep 9, 2015
c1e9fbc
add nodename
Sep 9, 2015
33dbb75
add nodename
Sep 9, 2015
c84c2a7
add nodename
Sep 9, 2015
d81f92c
add nodename
Sep 9, 2015
f17345f
add nodename
Sep 9, 2015
e961c23
add nodename
Sep 9, 2015
f476dbc
add nodename
Sep 9, 2015
c0005eb
add nodename
Sep 9, 2015
7ac04b2
logs
Sep 9, 2015
0955228
service name
Sep 9, 2015
bd703cc
service name
Sep 9, 2015
822670e
service name
Sep 9, 2015
f699e67
service name
Sep 9, 2015
1452fc5
service name
Sep 9, 2015
93a240c
service name
Sep 9, 2015
994984f
service name
Sep 9, 2015
6ba4238
temp change
Oct 12, 2015
9c4c201
temp change
Oct 12, 2015
76fc756
temp change
Oct 12, 2015
e321d01
temp change
Oct 12, 2015
adbf736
temp change
Oct 12, 2015
7946e77
debug
Oct 12, 2015
c14c2c2
debug
Oct 12, 2015
193e948
Merge remote-tracking branch 'upstream/master'
Oct 12, 2015
2141aaf
temp change
Oct 12, 2015
7acd740
break up cmds
Oct 13, 2015
5dde7f2
break up cmds
Oct 13, 2015
0fa7acf
break up cmds
Oct 13, 2015
a756a35
break up cmds
Oct 13, 2015
2e0c530
break up cmds
Oct 13, 2015
b68e3ef
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 14, 2015
4ae220d
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 14, 2015
da02ccb
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 14, 2015
45274cd
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 14, 2015
9acd2c4
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 14, 2015
e824d80
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 14, 2015
f6f02bc
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 14, 2015
8805f30
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 14, 2015
83651bb
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
2bbbb7c
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
fcdbf4a
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
e8d68b6
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
3d9aa98
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
fa02263
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
d2c1e01
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
91af594
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
b244e2d
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
3bbaf14
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
de74bcd
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
0710c14
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
0c7888c
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
fb99124
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
09852fa
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
bc38898
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
f8753f0
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
ef8baa3
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
3ad5339
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
f5637f8
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
2ce6fd1
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
b4948c7
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
2bb5ae1
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
a3400af
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
99e5d68
avoid use of ADDITIONAL_PREPROCESS_CMDS since its not supported for e…
Oct 15, 2015
41e6dde
modified uri for agent download
Oct 16, 2015
09fda72
modified uri for agent download
Oct 16, 2015
3bd6c6e
modified uri for agent download
Oct 16, 2015
44bd0d5
modified uri for agent download
Oct 16, 2015
1993064
modified uri for agent download
Oct 19, 2015
d86fde3
modified uri for agent download
Oct 19, 2015
964a40c
modified uri for agent download
Oct 19, 2015
272dd52
modified uri for agent download
Oct 19, 2015
2d37a1e
modified uri for agent download
Oct 19, 2015
a8b68ee
modified uri for agent download
Oct 19, 2015
68edde7
modified uri for agent download
Oct 19, 2015
b88f396
modified uri for agent download
Oct 19, 2015
86ca8f1
modified uri for agent download
Oct 19, 2015
77dab05
modified uri for agent download
Oct 19, 2015
653dcc5
modified uri for agent download
Oct 19, 2015
4640dda
modified uri for agent download
Oct 19, 2015
f346fd5
modified uri for agent download
Oct 19, 2015
99f94ef
modified uri for agent download
Oct 19, 2015
11e43ce
modified uri for agent download
Oct 19, 2015
623f7c5
add handling for cups svc
Oct 28, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
213 changes: 213 additions & 0 deletions extensions/appdynamics/extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""AppDynamics Extension

Downloads, installs and configures the AppDynamics agent for PHP
"""
import os
import os.path
import logging


_log = logging.getLogger('appdynamics')


#DEFAULTS = {
# 'APPDYNAMICS_HOST': 's3-us-west-2.amazonaws.com/niksappd',
# 'APPDYNAMICS_VERSION': '4.1.1.0',
# 'APPDYNAMICS_PACKAGE': 'appdynamics-php-agent-x64-linux-{APPDYNAMICS_VERSION}.tar.gz',
# 'APPDYNAMICS_DOWNLOAD_URL': 'https://{APPDYNAMICS_HOST}/php_agent/'
# 'archive/{APPDYNAMICS_VERSION}/{APPDYNAMICS_PACKAGE}',
#}

DEFAULTS = {
'APPDYNAMICS_HOST': 'packages.appdynamics.com',
'APPDYNAMICS_VERSION': '4.1.5.0',
'APPDYNAMICS_PACKAGE': 'appdynamics-php-agent-x64-linux-{APPDYNAMICS_VERSION}.tar.bz2',
'APPDYNAMICS_DOWNLOAD_URL': 'https://{APPDYNAMICS_HOST}/'
'php/{APPDYNAMICS_VERSION}/{APPDYNAMICS_PACKAGE}',
}

class AppDynamicsInstaller(object):
def __init__(self, ctx):
self._log = _log
self._ctx = ctx
self._detected = False
self.app_name = None
self.account_access_key = None
try:
self._log.info("Initializing")
if ctx['PHP_VM'] == 'php':
self._merge_defaults()
self._load_service_info()
self._load_php_info()
self._load_appdynamics_info()
except Exception:
self._log.exception("Error installing AppDynamics! "
"AppDynamics will not be available.")

def _merge_defaults(self):
for key, val in DEFAULTS.iteritems():
if key not in self._ctx:
self._ctx[key] = val

def _load_service_info(self):
self._log.info("Loading AppDynamics service info.")
services = self._ctx.get('VCAP_SERVICES', {})
service_defs = services.get('appdynamics', [])
if len(service_defs) == 0:
self._log.info("AppDynamics services with tag appdynamics not detected.")
self._log.info("Looking for tag app-dynamics service.")
service_defs = services.get('app-dynamics', [])
if len(service_defs) == 0:
self._log.info("AppDynamics services with tag app-dynamics not detected.")
self._log.info("Looking for Appdynamics user-provided service.")
service_defs = services.get('user-provided', [])
if len(service_defs) == 0:
self._log.info("AppDynamics services not detected.")
if len(service_defs) > 1:
self._log.warn("Multiple AppDynamics services found, "
"credentials from first one.")
if len(service_defs) > 0:
service = service_defs[0]
creds = service.get('credentials', {})
self.account_access_key = creds.get('account-access-key', None)
if self.account_access_key:
self._log.debug("AppDynamics service detected.")
self._detected = True

def _load_appdynamics_info(self):
vcap_app = self._ctx.get('VCAP_APPLICATION', {})
self.app_name = vcap_app.get('name', None)
self._log.debug("App Name [%s]", self.app_name)

if 'APPDYNAMICS_LICENSE' in self._ctx.keys():
if self._detected:
self._log.warn("Detected a AppDynamics Service & Manual Key,"
" using the manual key.")
self.license_key = self._ctx['APPDYNAMICS_LICENSE']
self._detected = True

if self._detected:
appdynamics_so_name = 'appdynamics-%s%s.so' % (
self._php_api, (self._php_zts and 'zts' or ''))
self.appdynamics_so = os.path.join('@{HOME}', 'appdynamics',
'agent', self._php_arch,
appdynamics_so_name)
self._log.debug("PHP Extension [%s]", self.appdynamics_so)
self.log_path = os.path.join('@{HOME}', 'logs',
'appdynamics-daemon.log')
self._log.debug("Log Path [%s]", self.log_path)
self.daemon_path = os.path.join(
'@{HOME}', 'appdynamics', 'daemon',
'appdynamics-daemon.%s' % self._php_arch)
self._log.debug("Daemon [%s]", self.daemon_path)
self.socket_path = os.path.join('@{HOME}', 'appdynamics',
'daemon.sock')
self._log.debug("Socket [%s]", self.socket_path)
self.pid_path = os.path.join('@{HOME}', 'appdynamics',
'daemon.pid')
self._log.debug("Pid File [%s]", self.pid_path)

def _load_php_info(self):
self.php_ini_path = os.path.join(self._ctx['BUILD_DIR'],
'php', 'etc', 'php.ini')
self._php_extn_dir = self._find_php_extn_dir()
self._php_api, self._php_zts = self._parse_php_api()
self._php_arch = self._ctx.get('APPDYNAMICS_ARCH', 'x64')
self._log.debug("PHP API [%s] Arch [%s]",
self._php_api, self._php_arch)

def _find_php_extn_dir(self):
with open(self.php_ini_path, 'rt') as php_ini:
for line in php_ini.readlines():
if line.startswith('extension_dir'):
(key, val) = line.strip().split(' = ')
return val.strip('"')

def _parse_php_api(self):
tmp = os.path.basename(self._php_extn_dir)
php_api = tmp.split('-')[-1]
php_zts = (tmp.find('non-zts') == -1)
return php_api, php_zts

def should_install(self):
return self._detected

# Extension Methods
def preprocess_commands(ctx):

service = ctx.get('VCAP_SERVICES', {})
service_defs = service.get('appdynamics', [])
detected = False
if len(service_defs) == 0:
_log.info("AppDynamics services with tag appdynamics not detected.")
_log.info("Looking for tag app-dynamics service.")
service_defs = service.get('app-dynamics', [])
if len(service_defs) == 0:
_log.info("AppDynamics services with tag app-dynamics not detected.")
_log.info("Looking for Appdynamics user-provided service.")
cups_service_defs = service.get('user-provided', [])

if len(cups_service_defs) == 0:
_log.info("AppDynamics services not detected.")
else:
cups_svc = cups_service_defs.get('name', [])
if cups_svc == "appdynamics" || cups_svc == "app-dynamics":
_log.info("AppDynamics cups services detected.")
detected = True

if len(service_defs) > 0:
_log.debug("AppDynamics service detected.")
detected = True

if detected == True:
exit_code = os.system("echo preprocess_commands: AppDynamics agent configuration")
return [[ 'echo', '" in preprocess;"'],
['env'],
[ 'chmod', ' -R 755 /home/vcap/app'],
[ 'chmod', ' 777 ./app/appdynamics/appdynamics-php-agent/logs'],
[ 'export', ' APP_TIERNAME=`echo $VCAP_APPLICATION | sed -e \'s/.*application_name.:.//g;s/\".*application_uri.*//g\' `'],
[ 'if [ -z $application_name ]; then export APP_NAME=$APP_TIERNAME && APP_TIERNAME=$APP_TIERNAME-tier; else export APP_NAME=$application_name; fi'],
[ 'export', ' APP_HOSTNAME=$APP_TIERNAME-`echo $VCAP_APPLICATION | sed -e \'s/.*instance_index.://g;s/\".*host.*//g\' | sed \'s/,//\' `'],
[ 'export', ' AD_ACCOUNT_NAME=`echo $VCAP_SERVICES | sed -e \'s/.*account-name.:.//g;s/\".*port.*//g\' `'],
[ 'export', ' AD_ACCOUNT_ACCESS_KEY=`echo $VCAP_SERVICES | sed -e \'s/.*account-access-key.:.//g;s/\".*host-name.*//g\' `'],
[ 'export', ' AD_CONTROLLER=`echo $VCAP_SERVICES | sed -e \'s/.*host-name.:.//g;s/\".*ssl-enabled.*//g\' `'],
[ 'export', ' AD_PORT=`echo $VCAP_SERVICES | sed -e \'s/.*port.:.//g;s/\".*account-access-key.*//g\' `'],
[ 'export', ' sslenabled=`echo $VCAP_SERVICES | sed -e \'s/.*ssl-enabled.:.//g;s/\".*.*//g\'`'],
[ 'if [ $sslenabled == \"true\" ] ; then export sslflag=-s ; fi; '],
[ 'echo sslflag set to $sslflag' ],
[ 'PATH=$PATH:./app/php/bin/ ./app/appdynamics/appdynamics-php-agent/install.sh $sslflag -i ./app/appdynamics/phpini -a=$AD_ACCOUNT_NAME@$AD_ACCOUNT_ACCESS_KEY $AD_CONTROLLER $AD_PORT $APP_NAME $APP_TIERNAME $APP_HOSTNAME' ],
[ 'cat', ' /home/vcap/app/appdynamics/phpini/appdynamics_agent.ini >> /home/vcap/app/php/etc/php.ini'],
[ 'cat', ' /home/vcap/app/appdynamics/phpini/appdynamics_agent.ini'],
[ 'echo', '"done preprocess"'],
['env']]
else:
return ()

def service_commands(ctx):
return {}


def service_environment(ctx):
return {}

def compile(install):
appdynamics = AppDynamicsInstaller(install.builder._ctx)
if appdynamics.should_install():
_log.info("Installing AppDynamics")
install.package('APPDYNAMICS')
_log.info("AppDynamics Installed.")
return 0
9 changes: 9 additions & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ exclude_files:
- php_buildpack-*v*

url_to_dependency_map:
- match: appdynamics-php-agent-x64-linux-(\d+\.\d+\.\d+\.\d+)
name: appdynamics
version: "$1"
- match: newrelic-php5-(\d+\.\d+\.\d+\.\d+)-linux
name: newrelic
version: "$1"
Expand All @@ -26,6 +29,12 @@ url_to_dependency_map:
version: "$1"

dependencies:
- name: appdynamics
version: 4.1.1.0
uri: https://s3-us-west-2.amazonaws.com/niksappd/appdynamics-php-agent-x64-linux-4.1.1.0.tar.gz
cf_stacks:
- cflinuxfs2
md5: cd9dbe7e3cc51031db1e429fbc934b64
- name: newrelic
version: 4.23.3.111
uri: https://download.newrelic.com/php_agent/archive/4.23.3.111/newrelic-php5-4.23.3.111-linux.tar.gz
Expand Down
Loading